المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Data connection from C# web service



C# Programming
09-30-2009, 06:52 AM
http://www.barakasoft.com/script/Forums/Images/smiley_mad.gif http://www.barakasoft.com/script/Forums/Images/smiley_mad.gif http://www.barakasoft.com/script/Forums/Images/smiley_mad.gif
I am writing an XML web service in VS2008 using C#. SQL and VS are running on the same box. There are several SQL instances running because we are using the box to support our customers who are mixed 2005/2008 SQL server. From inside VS I can create a data connection to one of our SQL instances. The box is ESSERV and the instance is ES2008 so the connection string that is in the connection object is:

"Data Source=ESSERV\ES2008;Initial Catalog=ESData08;Integrated Security=True"

This works fine. I can see the ESData08 database, tables, SPs, etc. No problems. So in C# I use the following code:

String sqlConn = "Data Source=ESSERV/ES2008;Initial Catalog=ESData08;Integrated Security=True";
SqlConnection esConn = new SqlConnection(sqlConn);
esConn.Open();

YES, I flipped the backslash between ESSERV and ES2008 to a forward slash. MSDN said that was OK to do so it doesn't look like an escape sequence. And here is part of what I get:

System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at System.Data.SqlClient.SqlInternalConnection........... and about 2 dozen more lines of error.

So my question is WHY? I have tried every combination of ESSERV\ES2008 and all of them give me the same error. Named Pipes are enabled. So what is causing this error and is there a way to specify the data connection I have already defined and know works. I'm kind of new to VS and C# but I'm sure that the code is correct as it compiles and runs up to the open. Any help with this nightmare would be appreciated.

Thanks,

Joe B