bool OpenDB(CSession* pSession)
{
ATLASSERT(pSession != NULL);
bool bRet = false;
pSession->Close();
TCHAR szFilePath[1024];
::GetModuleFileName(_Module.m_hInst, szFilePath, sizeof(szFilePath) / sizeof(TCHAR) -1);
TCHAR drive[_MAX_DRIVE];
TCHAR direc[_MAX_DIR];
TCHAR fname[_MAX_FNAME];
TCHAR ext[_MAX_EXT];
_tsplitpath(szFilePath, drive, direc, fname, ext);
TCHAR pszDBConnFile[1024] = {0};
_tmakepath(pszDBConnFile,drive,direc,_T("config"),_T("ini"));
TCHAR pszServer[1024] = {0};
TCHAR pszUID[1024] = {0};
TCHAR pszPWD[1024] = {0};
DWORD dw = GetPrivateProfileString(_T("SDDB"),_T("Server"),_T(""),pszServer,sizeof(pszServer)/sizeof(TCHAR) -1,pszDBConnFile);
pszServer[dw] = 0;
dw = GetPrivateProfileString(_T("SDDB"),_T("UserName"),_T(""),pszUID,sizeof(pszUID)/sizeof(TCHAR) -1,pszDBConnFile);
pszUID[dw] = 0;
dw = GetPrivateProfileString(_T("SDDB"),_T("UserPasswd"),_T(""),pszPWD,sizeof(pszPWD)/sizeof(TCHAR) -1,pszDBConnFile);
pszPWD[dw] = 0;
if((_tcslen(pszServer) > 0) && (_tcslen(pszUID) > 0))
{
HRESULT hr;
CDataSource db;
CDBPropSet dbinit(DBPROPSET_DBINIT);
dbinit.AddProperty(DBPROP_AUTH_PASSWORD, pszPWD);
dbinit.AddProperty(DBPROP_AUTH_USERID, pszUID);
dbinit.AddProperty(DBPROP_INIT_DATASOURCE, pszServer);
dbinit.AddProperty(DBPROP_INIT_LCID, (long)2052);
dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, OLESTR(""));
hr = db.Open(_T("OraOLEDB.Oracle"), &dbinit);
if(hr == S_OK)
{
bRet = (pSession->Open(db) == S_OK);
}
}
return bRet;
}
opendb
最新推荐文章于 2023-02-13 20:15:00 发布