I’m new to SQLClient, working in VS2008 and attempting to connect to an SQL server 2005 SQL Express instance on my local machine.
I’ve been trying different combinations of quote marks, capital letters, and other things, and I can’t seem to get the connection.
My code is
using namespace System::Data::SqlClient ;
...
String^ connectionString = "Server=MY-PC\SQLEXPRESS; Database=myDB; Trusted_Connection=True; " ;
SqlConnection^ connection = gcnew SqlConnection(connectionString) ;
connection->Open() ;
where MY-PC is the machine name.
The error is “The server was not found or was not accessible. “
Is there something obviously wrong?
Thanks,
Melanie
You need two backslashes there, otherwise it treats \S as an escape character.
Also, it might be simpler to use (local)\SQLEXPRESS instead of your machine’s name to get around any DNS configuration issues that might be haunting you.
Finally, make sure your database is allowing connections.