给的代码不完整。先确保你的m_pConn有没有调用CreateInstance创建
用下面代码看看_bstr_t strDsn,str_db_user,str_db_pwd;
_ConnectionPtr pConnection;
...
try{
pRecordset.CreateInstance("ADODB.RecordSet");
pConnection->Open(strDsn,str_db_user,str_db_pwd,adConnectUnspecified);
}
catch(_com_error e){
if(pConnection!=NULL && pConnection->State){
pConnection->Close();
}
pConnection=NULL;
}
用下面代码看看_bstr_t strDsn,str_db_user,str_db_pwd;
_ConnectionPtr pConnection;
...
try{
pRecordset.CreateInstance("ADODB.RecordSet");
pConnection->Open(strDsn,str_db_user,str_db_pwd,adConnectUnspecified);
}
catch(_com_error e){
if(pConnection!=NULL && pConnection->State){
pConnection->Close();
}
pConnection=NULL;
}
解决方案 »
- 求RingSDK界面库(临风大侠)最新版
- DEBUG调试正常,直接运行程序有错误
- 从list中如何取到其中的元素?
- bho的dll中如何调用activex控件
- 如何写键盘缓冲
- 奇怪的问题,也可能是很菜的问题,请高手指教!
- 不用函数:CreateDirectory(),怎样判断在当前目录下是否存在某一个指定的目录?
- error C2440: 'type cast' : cannot convert from 'long (__thiscall CEditBaseApp::*
- 关于 Unicode 的问题, 请高手帮助
- 我想学vc,谁知道哪本书好?
- 请问怎样给喜欢的女孩子写信呀!
- 哪位大侠用过InternetGetConnectedStateEx 这个API?请教
example from MSDN..
///////////////////////////////////////////////////////////
// //
// PrintProviderError Function //
// //
///////////////////////////////////////////////////////////void PrintProviderError(_ConnectionPtr pConnection)
{
//Define Other Variables
HRESULT hr = S_OK;
_bstr_t strError;
ErrorPtr pErr = NULL; try
{
// Enumerate Errors collection and display
// properties of each Error object.
long nCount = pConnection->Errors->Count; // Collection ranges from 0 to nCount - 1.
for(long i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("Error #%d\n", pErr->Number);
printf("\t %s\n",(LPCSTR)pErr->Description);
printf("\t(Source: %s)\n",(LPCSTR)pErr->Source);
printf("\t(SQL State: %s)\n",(LPCSTR)pErr->SQLState);
printf("\t(NativeError: %d)\n",(LPCSTR)pErr->NativeError);
if ((LPCSTR)pErr->GetHelpFile() == NULL)
{
printf("\tNo Help file available\n");
}
else
{
printf("\t(HelpFile: %s\n)" ,pErr->HelpFile);
printf("\t(HelpContext: %s\n)" , pErr->HelpContext);
}
}
}
catch(_com_error &e)
{
// Notify the user of errors if any.
PrintComError(e);
}
}///////////////////////////////////////////////////////////
// //
// PrintComError Function //
// //
///////////////////////////////////////////////////////////void PrintComError(_com_error &e)
{
// Notify the user of errors if any.
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// Print Com errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}