SQL connection in Visual studio 2012
-
I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();
-
I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();
-
I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();
If you want to attach a specific database file with the "user instance" feature, you need to change your connection string: http://www.connectionstrings.com/sqlconnection/using-an-user-instance-on-a-local-sql-server-express-instance/[^] Otherwise, you need to attach the database file to the server before you can connect to it. You then specify the name of the database, not the path to the database file, in the connection string.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I tried to remove the integrated securit from connection string but i got the same error. ISP is just a self-definend variabile used ro build the connection string. Thanks again eddy
-
I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();
There are some issues with your connection string. "Database" is the *name* of the database in SQL Server (as you can see it e.g. in SQL Server Management Studio), not the path to the database file. "Integrated Security=true" means that you login with your Windows Credentials. That means, your Windows user must have access rights to the databse. If you want to use a specific (database defined) user, do not use Integrated Security, but set username and password instead. For more information, look at http://www.connectionstrings.com/sql-server/[^].