??????VC??MFC??????SQL Server???????????afxoleinit???????????????????????????????
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);
//?????????
try
{
m_pConnection->Open(_bstr_t(bcnstr)??_bstr_t(bunstr)??
_bstr_t(bpwdstr)??-1);//adOpenUnspecified
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Warning: ?????????????. ???????: %s; ???: %s; ??: %d "?? e.ErrorMessage()?? __FILE__?? __LINE__);
AfxMessageBox(errormessage);
}
catch(...)
{
AfxMessageBox("Warning :??????????????δ?????");
}
}
void smsLogon::ExitDB()     //????????????????
{
if(m_pConnection!=NULL)
{
m_pConnection->Close();//???????
m_pConnection.Release();//??????
}
}