VS2010中MFC连接数据库时查询出错
我是打算用一个按钮来查询数据库,我先在开始include了一个文件,如下#include"Debug\msado15.tlh"然后我在按钮中的查询代码如下CoInitia...
我是打算用一个按钮来查询数据库,我先在开始include了一个文件,如下
#include "Debug\msado15.tlh"
然后我在按钮中的查询代码如下
CoInitialize(NULL);
_ConnectionPtr pConnection;
//_CommandPtr pCommand;
_RecordsetPtr pRecordset(_uuidof(Recordset));
pConnection.CreateInstance(_uuidof(Connection));
//pCommand.CreateInstance(_uuidof(Command));
pConnection->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=123;Initial Catalog=LCTAN";
pConnection->Open("","","",adConnectUnspecified);
//pCommand->ActiveConnection=pConnection;
pRecordset=pConnection->Execute("select * from TAN",NULL,adCmdText);
while(!pRecordset->rsEOF);
{
((CListBox*)GetDlgItem(IDC_LIST_ShowSQL))->AddString((_bstr_t)pRecordset->GetCollect("NodeNumber"));
pRecordset->MoveNext();
}
pRecordset->Close();
pConnection->Close();
pRecordset.Release();
pConnection.Release();
CoUninitialize();
然后我单击按钮,在卡了2秒之后报出如图的错误,sa帐号的密码已经在SQL2008中改过,数据库也已经测试可连接,为什么还会出现这个 问题呢? 展开
#include "Debug\msado15.tlh"
然后我在按钮中的查询代码如下
CoInitialize(NULL);
_ConnectionPtr pConnection;
//_CommandPtr pCommand;
_RecordsetPtr pRecordset(_uuidof(Recordset));
pConnection.CreateInstance(_uuidof(Connection));
//pCommand.CreateInstance(_uuidof(Command));
pConnection->ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;pwd=123;Initial Catalog=LCTAN";
pConnection->Open("","","",adConnectUnspecified);
//pCommand->ActiveConnection=pConnection;
pRecordset=pConnection->Execute("select * from TAN",NULL,adCmdText);
while(!pRecordset->rsEOF);
{
((CListBox*)GetDlgItem(IDC_LIST_ShowSQL))->AddString((_bstr_t)pRecordset->GetCollect("NodeNumber"));
pRecordset->MoveNext();
}
pRecordset->Close();
pConnection->Close();
pRecordset.Release();
pConnection.Release();
CoUninitialize();
然后我单击按钮,在卡了2秒之后报出如图的错误,sa帐号的密码已经在SQL2008中改过,数据库也已经测试可连接,为什么还会出现这个 问题呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询