Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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 ! ");
...
Posted
Updated 31-Jan-17 19:32pm
v5
Comments
CPallini 18-Sep-12 4:54am    
What does it mean "can't fetch the data'". Did you get any error?

Your conn string point to catalog "master"

I feel this is the culprit::

connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=master ;Integrated Security=True";
 
Share this answer
 
v2
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.
 
Share this answer
 
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..........
 
Share this answer
 
i think you don't have data for the query
select * from spt_fallback_dev
first run it in your Sql server
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900