We help IT Professionals succeed at work.

MS SqlConnection string

jtequia asked
I moved a database from a 2005 SQL server with no named Instance to a 2005 SQL server with a named Instanced, I changed the connection string to reflect the new server name however when I rebuild the C# solution and launch the application it's says I'm missing the instance name. I tried adding the instance to the server name i.e. gpvelocity"+"5.gpsecurity\HIRSCH and it didn't work.

This is the original connection string to the old server which works:
sqlConn.ConnectionString = "user id=sa;data source=gpvelocity" + "6.gpsecurity;persist security info=True;initial catalog=Velocity;password=123";
Watch Question


Yes that was the first place I checked, but I need to include the user and password in the string.

if you are using c# try to escape \ by using \\


Usually need to use servername\instancename:

data source=servername\instancename


sqlConn.ConnectionString = @"user id=sa;data source=gpvelocity6.gpsecurity\HIRSCH;persist security info=True;initial catalog=Velocity;password=123";

I may be just being a lunk-head but not sure why you concatenating (+) so I just plugged in the @"" to ignore the c# delimiter(\)

If you're still stuck one easy thing that can help is to make a connection to your server using the "Server Explorer" in VS then highlight it when your done and look at the properties (can right click and choose properties if you want).

Can test the connection during the "add" wizard (can actually see the conn string in the advanced section as well).

Then again your new instance may not be correctly setup for connections (but that doesnt necessarily match the error you are getting). In any case using the Solution Explorer would also help you see if this was the case.

Hope that helps.


Thanks it worked like a charm :)