Click here to Skip to main content
Sign Up to vote bad
good
See more: 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 ! ");
...
Posted 17-Sep-12 22:39pm
Edited 18-Sep-12 8:19am

Comments
CPallini - 18-Sep-12 4:54am
What does it mean "can't fetch the data'". Did you get any error?

4 solutions

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.
  Permalink  
i think you don't have data for the query
select * from spt_fallback_dev
first run it in your Sql server
  Permalink  
Your conn string point to catalog "master"
 
I feel this is the culprit::
 
 connetionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=master ;Integrated Security=True";
  Permalink  
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..........
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 544
1 Ron Beyer 296
2 OriginalGriff 258
3 samadhan_kshirsagar 229
4 Tadit Dash 193
0 Sergey Alexandrovich Kryukov 7,007
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 2,975


Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid