I am having issues to connect to a database from a C++ program (VS 2008).
I have created the database using SQL Server and both SQL Server and SQL Server Browser are running, TCP/IP and Remote Access开发者_Go百科 are enabled.
I can connect to my database using sqlcmd, but when I use:
System::Data::SqlClient::SqlConnection ^_SqlConnection = gcnew System::Data::SqlClient::SqlConnection();
_SqlConnection->ConnectionString = "Data Source=MyComp\SQLEXPRESS; Initial Catalog=DbName; Integrated Security=True";
_SqlConnection->Open();
I get the classic error
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
I have copied the connection string from the database properties found in the Server Explorer of VS, so I guess it's correct.
Thanks a lot for any help.
Found the solution. Correct syntax for connection string is:
"Data Source=MyComp\\SQLEXPRESS; Initial Catalog=DbName; Integrated Security=True";
With 2 back-slashes \\ in the server name.
精彩评论