MFC用ADO链接数据库,出现这个错误 10
thisapplicationhasrequestedtheruntimetoterminateitinanunsualway,pleasecontacttheappli...
this application has requested the runtime to terminate it in an unsual way ,please contact the application's support team for more information。并且SQL点安全性的时候出现错误:一个或多个数据库无法访问,因而将不会在数据库访问选项卡中显示。这两个是不是有关系啊,求解
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRes(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command));
pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=ss";
pConn->Open("", "",//用户名
"",//密码,已经在连接字符串中指定
adConnectUnspecified//-1:同步打开连接,adAsyncConnect=16:异步打开连接,在Asp中要用值
);
pCmd->put_ActiveConnection(_variant_t((IDispatch*)pConn));
pCmd->CommandText="select * from authors";
pRes=pCmd->Execute(NULL,NULL,adCmdText);
//MessageBox("PLC报警!","对话框",MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL);
while(!pRes->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRes->GetCollect("au_lname"));
pRes->MoveNext();
}
pRes->Close();
pConn->Close();
pCmd.Release();//
pRes.Release();
pConn.Release();
CoUninitialize(); 展开
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRes(__uuidof(Recordset));
_CommandPtr pCmd(__uuidof(Command));
pConn->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=ss";
pConn->Open("", "",//用户名
"",//密码,已经在连接字符串中指定
adConnectUnspecified//-1:同步打开连接,adAsyncConnect=16:异步打开连接,在Asp中要用值
);
pCmd->put_ActiveConnection(_variant_t((IDispatch*)pConn));
pCmd->CommandText="select * from authors";
pRes=pCmd->Execute(NULL,NULL,adCmdText);
//MessageBox("PLC报警!","对话框",MB_YESNO|MB_ICONQUESTION|MB_SYSTEMMODAL);
while(!pRes->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRes->GetCollect("au_lname"));
pRes->MoveNext();
}
pRes->Close();
pConn->Close();
pCmd.Release();//
pRes.Release();
pConn.Release();
CoUninitialize(); 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询