Welcome to the CC ++ programming Community Forum and interact with 2 million technical staff to enter voidsmsLogon: InitSQLServer (CStringserver, CStringdb, CStringUserName, CStringPwd) {m_pConnection.CreateInstance (ADODB. connection); CStringstrCn; strCn. empty (); strCnprov
Welcome to the C/C ++ programming Community Forum and interact with 2 million technicians> enter void smsLogon: InitSQLServer (CString server, CString db, CString UserName, CString Pwd) {m_pConnection.CreateInstance ("ADODB. connection "); CString strCn; strCn. empty (); strCn = "prov
Welcome to the C/C ++ programming Community Forum and interact with 2 million technical staff> enter
Void smsLogon: InitSQLServer (CString server, CString db, CString UserName, CString Pwd)
{
M_pConnection.CreateInstance ("ADODB. Connection ");
CString strCn;
StrCn. Empty ();
StrCn = "provider = SQLOLEDB; data source =" + server
+ "; Initial catalog =" + db
+ "; UserID =" + UserName
+ "; PassWord =" + Pwd;
_ Variant_t bcnstr = _ variant_t (strCn );
_ Variant_t bunstr = _ variant_t (UserName );
_ Variant_t bpwdstr = _ variant_t (Pwd );
// Open a connection
Try
{
M_pConnection-> Open (_ bstr_t (bcnstr), _ bstr_t (bunstr ),
_ Bstr_t (bpwdstr),-1); // adOpenUnspecified
}
Catch (_ com_error e)
{
CString errormessage;
Errormessage. format ("Warning: An exception occurred when connecting to the database. error message: % s; file: % s; row: % d \ n ", e. errorMessage (), _ FILE __, _ LINE __);
AfxMessageBox (errormessage );
}
Catch (...)
{
AfxMessageBox ("Warning: Unknown error occurred when connecting to the Database ");
}
}
Void smsLogon: ExitDB () // close the database connection when exiting
{
If (m_pConnection! = NULL)
{
M_pConnection-> Close (); // Close the connection
M_pConnection.Release (); // release an object
}
}