UPDATE: I have determined that the SQLClient code times out on the first call, but works on all subsequent calls. Also, when connecting with Management Studio, it times out the first time as well, then connects when I try again. Ideas?
Original: Hey guys, I have a very strange issue that I can't seem to resolve. I have an application that connects to several different versions of SQL Server. I have no problems connecting to 2005 or 2008 R2. But I am having timeout issues with 2008 Standard. I even wrote a sample app to try and troubleshoot this. Here's the sample code that works:
OdbcConnection conn = null;
OdbcDataAdapter adp = null;
DataSet resultSet = new DataSet();
DataTable result = null;
string queryString = Query.Text;
conn = new OdbcConnection(@"Driver={SQL Server Native Client 10.0};Server=MyServer\DataSource;Database=MyDatabase;Uid=MyUser;Pwd=ThePassword;");
conn.Open();
adp = new OdbcDataAdapter(queryString, conn);
adp.Fill(resultSet);
result = resultSet.Tables[0];
ResultsGrid.DataSource = result;
Now here the sample code that times out:
SqlConnection conn = null;
SqlDataAdapter adp = null;
DataSet resultSet = new DataSet();
DataTable result = null;
string queryString = Query.Text;
conn = new SqlConnection(Application Name=HCGPrevision; Data Source=MyServer\DataSource; Initial Catalog=MyDatabase;UID=MyUser;PWD=ThePassword;);
conn.Open();
adp = new SqlDataAdapter(queryString, conn);
adp.Fill(resultSet);
result = resultSet.Tables[0]; //Assume only one result set/table.
ResultsGrid.DataSource = result;
This second set of code will work on a database in SQL Server 2008 R2, but not the Standard/R1 version. The connection string seems to work fine for any other SQL Server but won't work for this one. We have been using this code for over 5 years and never had this issue. I made sure that SQL has Named Pipes enabled and Mixed (Windows/SQL) Authentication. The fact that the ODBC will work but not the SQL is bizarre. Please let me know what I'm missing!
Thanks,
Erick