Retrieves the hr;
Try
{
Hr=m_pConnection. CreateInstance (" ADODB. Connection ");
If (SUCCEEDED (hr))
{
M_pConnection - & gt; The ConnectionString="Data Source=keqw \ SQLEXPRESS PC - 20160413; Integrated Security=False; User ID=sa; Password=112358; The Connect Timeout=15; Encrypt=False; TrustServerCertificate=False ";
M_pConnection - & gt; Open (" ", ""," ", adConnectUnspecified);
M_pConnection - & gt; DefaultDatabase="PM".
//m_pConnection - & gt; ConnectionTimeout=2;///set the timeout time to 2 seconds,
//hr=m_pConnection - & gt; Open (" driver={SQL Server}; Server=keqw \ SQLEXPRESS PC - 20160413; The DATABASE=PM;" , "sa", "112358", adModeUnknown);
//hr=m_pConnection - & gt; Open (" Data Source=keqw \ SQLEXPRESS PC - 20160413; Integrated Security=False; User ID=sa; Password=112358; The Connect Timeout=15; Encrypt=False; TrustServerCertificate=False ", ""," ", adModeUnknown);
}
The else
MessageBox (" connect to the database failed ");
}
Catch _com_error (e)
{
//cstrings log;
//the Format (" connect to database failure! \ r \ n the reason: % s ", e.E rrorMessage ());
//MessageBox (log);
Getcomerror (" SQL_Connect1 ", e);
}
I use the SQL server2012 vs2012 connections, the above code throws an exception - e {DB_E_ERRORSOCCURRED Multiple - step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.} _com_error
Use vs2012 SQL Server object explorer can normal connection, the connection string is used above, turn to the great god how to solve this problem, thank you very much!
CodePudding user response:
PC - 20160413 keqw \ SQLEXPRESSChange
PC - 20160413 keqw \ \ SQLEXPRESS
\ remember to \ \ C.
CodePudding user response:
Change the still is not working,CodePudding user response:
Search "database connection string?"CodePudding user response:
Can use ADO assistant help to test the connection string,CodePudding user response:
The