请高手帮忙注释下面的代码,我是没有搞明白,下面的代码使用什么方法连接到Sql数据库。代码如下:
//很有意思 是Login.ini,编译时要注意是否存在,不存在时程序出错
//
void CBookManageApp::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));
}
catch(_com_error)
{
Flag = FALSE;
MessageBox(0,"请检查系统配置信息", "数据库连接失败",MB_OK);
return;
}
catch(...)
{
AfxMessageBox("SYS Error");
return;
}
}