Sql server连接已打开但无法获取数据 [英] Sql server connection is open but can't fetch data

查看:96
本文介绍了Sql server连接已打开但无法获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!!

通过C#+ Visual Studio 2010连接Sql server是开放的。但它仍然无法获取数据。 (Sql server 2008 R2)



sql server连接的代码如下:

Hi!!
Sql server connection through C# + visual studio 2010 is open. But still it can't fetch data. (Sql server 2008 R2)

code for sql server connection is as follows:

string connetionString = null;
SqlConnection cnn;
connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=master ;Integrated Security=True";
cnn = new SqlConnection(connetionString);
try
{
   cnn.Open();
   SqlCommand thisCommand = cnn.CreateCommand(); 
   thisCommand.CommandText = "select  * from spt_fallback_dev";
   SqlDataReader thisReader = thisCommand.ExecuteReader();

   if ( thisReader.Read())
   {
      MessageBox.Show("its damn reading ");
   } 
   thisReader.Close();
   cnn.Close();

   MessageBox.Show("Connection Open ! ");
...

推荐答案

你的conn字符串指向目录 master



我觉得这是罪魁祸首::



Your conn string point to catalog "master"

I feel this is the culprit::

connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=master ;Integrated Security=True";


在SQL查询分析器中针对连接字符串指向的同一数据库运行查询。还要检查凭据。

如果您返回了1行或更多行,则必须添加调试器并查看您的程序是否抛出任何异常。



顺便说一下,我对我的master数据库运行了这个查询,没有返回任何行。
Run the query in a SQL query analyzer against the same database your connection string points to. Do check the credentials as well.
If you have 1 or more rows returned, you will have to add a debugger and see if your program is throwing any exceptions.

By the way, I ran this query against my master database and no rows were returned.




首先检查,

1)带凭证的连接字符串

2)使用sql profiler检查连接建立与否的天气。

3)运行查询sql server检查天气是否提供输出

也可能有错误。

4)调试c#代码以检查天气查询返回任何表或值。



检查以上内容。

它会起作用..........
Hi,
first check,
1) connection string with credentials
2) use sql profiler to check weather it connection is established or not.
3) run the query in sql server to check weather it is giving output or not
There might be an error also.
4) debug the c# code to check weather query returnning any table or value.

Check above things.
It will work..........


这篇关于Sql server连接已打开但无法获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆