Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connecting to a SQL server

Status
Not open for further replies.

Pipe2Path

Programmer
Aug 28, 2001
60
I am having some trouble connecting to my SQL server database. The name of the server as listed in Enterprise Manager is PIPE2PAT-CIV8A2\GRETZKY (Windows NT). This is under a SQL server group.

Here is the code I'm using in ado.net

SqlConnection nwindConn = new SqlConnection("Data Source=PIPE2PAT-CIV8A2\GRETZKY;Integrated Security=SSPI;Initial Catalog=northwind");

nwindConn.Open();

Now, when I compile this, it tells me I have an unrecognized escape sequence. If I take the PIPE2PAT-CIV8A2 out leaving only GRETZKY, I get a connection timeout when opening the connection.

The above code works just fine in VB6. Can anyone help?

Thanks in advance.
 
Try adding singel quotes...

SqlConnection nwindConn = new SqlConnection("Data Source='PIPE2PAT-CIV8A2\GRETZKY';Integrated Security=SSPI;Initial Catalog=northwind");
 
Connecting to a database can be a pain. I don't know if you just didn't show it or not, but remember, since the backslash is an escape character, you need to either precede your whole statement with an @, or add another \, so either:

(@"Data Source=PIPE2PAT-CIV8A2\GRETZKY...
^
OR ("Data Source=PIPE2PAT-CIV8A2\\GRETZKY...
^

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top