Home > Software engineering >  Turn to the great god! Abnormal visual studio2012 connection SQL server problem.
Turn to the great god! Abnormal visual studio2012 connection SQL server problem.

Time:11-02

: : CoInitialize (NULL);
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 \ SQLEXPRESS
Change
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
reference 3 floor zhao4zhong1 response:
search "database connection string?"


A great god can help me with it? Before the program I use hr=m_pConnection - & gt; Open (" driver={SQL Server}; Server=keqw \ SQLEXPRESS PC - 20160413; The DATABASE=PM;" , "sa", "112358", adModeUnknown); Can normal connection, as a result, the hard disk is broken, change a hard disk can't even after reshipment system,

CodePudding user response:

Confirm your sa password that's right,

CodePudding user response:

After using the query analyzer normal connection first in the written procedures,
  • Related