大家好,下面的代码,请高手解释一下:
void CBbbApp::IniAdo()
{
try
{
CString temp;
char filepath[MAX_PATH];
GetModuleFileName(NULL,filepath,MAX_PATH);
temp = theApp.ExtractFilePath(filepath);//获取可执行文件的路径
//m_pCon.CreateInstance("ADODB.Connection");
CString strAdoConn;
char temp1[100];
GetPrivateProfileString("DatabaseConfig","Server","",temp1,100,temp+"login.ini");
strserver = (TCHAR *)temp1;
GetPrivateProfileString("DatabaseConfig","Database","",temp1,100,temp+"login.ini");
strdbName = temp1;
GetPrivateProfileString("DatabaseConfig","User","",temp1,100,temp+"login.ini");
strUser = temp1;
GetPrivateProfileString("DatabaseConfig","PWD","",temp1,100,temp+"login.ini");
strPassword = temp1;
strAdoConn.Format("driver={SQL Server};SERVER=%s;UID=%s;PWD=%s;DATABASE=%s",
strserver, strUser, strPassword, strdbName);
m_pCon.CreateInstance(_uuidof(Connection));
m_pCon->ConnectionString = (_bstr_t)strAdoConn;
m_pCon->Open("","","",NULL);
m_pCom.CreateInstance("ADODB.Command");
m_pRs.CreateInstance(_uuidof(Recordset));
m_pRs1.CreateInstance(_uuidof(Recordset));
// ADOFLAG = TRUE;
}
catch(_com_error)
{
//ADOFLAG = FALSE;
Flag = FALSE;
MessageBox(0,"请检查系统配置信息", "数据库连接失败",MB_OK);
return;
}
catch(...)
{
AfxMessageBox("SYS Error");
return ;
}
}