4,011
社区成员
发帖
与我相关
我的任务
分享
//连接SQLServer
BOOL CDataADO::InitADO()
{ try {
char appPath[256];
GetCurrentDirectory(256,appPath); //取得应用程序当前路径
CString filePath; //保存Ini文件名
filePath.Format("%s",appPath);
filePath += "\\";
filePath += "SYS.INI";
CString strAdoConn;
char temp1[100];
GetPrivateProfileString("DatabaseConfig","Server","",temp1,100,filePath);
strserver = (TCHAR *)temp1;
GetPrivateProfileString("DatabaseConfig","Database","",temp1,100,filePath);
strdbName = temp1;
GetPrivateProfileString("DatabaseConfig","User","",temp1,100,filePath);
strUser = temp1;
GetPrivateProfileString("DatabaseConfig","PWD","",temp1,100,filePath);
strPassword = temp1;
strAdoConn.Format("Provider=SQLOLEDB.1;Password=%s;Persist Security Info=False;User ID=%s;Initial
Catalog=%s;Data Source=%s",strPassword,strUser,strdbName,strserver);
m_pCon.CreateInstance(_uuidof(Connection));
m_pCon->ConnectionString = (_bstr_t)strAdoConn;
m_pCon->Open("","","",NULL);
return TRUE;
}
catch(_com_error)
{
MessageBox(0,"请检查系统配置信息", "数据库连接失败",MB_OK|MB_ICONINFORMATION);
return FALSE;
} catch(...) {
MessageBox(0,"系统错误", "数据库连接失败",MB_OK|MB_ICONINFORMATION);
return FALSE ;
} }