_RecordsetPtr::Open()时,老是弹出:0x7c80bef7 处未处理的异常: Microsoft C++ 异常: 内存位置 0x0012f7d

yaoxuezhu312 2011-12-26 09:24:38
一下这段代码是连接数据库,根据特定条件读取相应的数据(COM组件注册是没有问题的,因为已经能够写进去了,就是不能读出来...)
小弟平常很少和数据库打交道,实在不知道这是啥原因...
麻烦各位老鸟们看看是不是代码哪里错了(生成的SQL语句是对的,我手动到数据库是能够查出相应的数据来的,就是用程序查找就出问题。虽然分是少了点,但还是希望大伙儿不腻赐教,小弟在此有礼了...)
CString strSQL;

_variant_t var;
_ConnectionPtr m_pConn;
_RecordsetPtr m_pRst;

HRESULT hr;


// 获取当前鼠标所指行的信息
int ItemNum = this->GetSelectionMark();
strID = this->GetItemText(ItemNum, 0);

strIP = this->GetItemText(ItemNum, 1);

strPort = this->GetItemText(ItemNum, 2);

hr = m_pConn.CreateInstance(__uuidof(Connection));
m_pRst.CreateInstance(__uuidof(Recordset));
m_pRst->CursorLocation = adUseClient;

m_pConn->ConnectionTimeout = DBTIMEOUT;
m_pConn->CommandTimeout = DBTIMEOUT;

strSQL.Format("select id,ip,port,remark,updatetime,starttime,sendnum,rcvnum,errnum,connnum,sendtra,rcvtra,clientdisc,monitorport,lowip,lownote,transferip,transfernote from serverport where id=%s",strID);

try{
m_pRst->Open(strSQL.GetBuffer(0),(IDispatch*)m_pConn,adOpenKeyset,adLockOptimistic,adCmdText);
...全文
914 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gold_water 2011-12-26
  • 打赏
  • 举报
回复
yaoxuezhu312 2011-12-26
  • 打赏
  • 举报
回复
问题已解决:
使用前没有进行连接 ,在打开前 增加了:
m_pconn->Open(theApp.m_strDBConnection.GetBuffer(0),"","",adModeUnknown);
没有再抛出异常了。

yaoxuezhu312 2011-12-26
  • 打赏
  • 举报
回复
我的开发环境是VS2008
连接的数据库是SQL Server 2008
yaoxuezhu312 2011-12-26
  • 打赏
  • 举报
回复
我在相应的地方加了'',即id='%s',但是还是进入:
catch(_com_error e)
{

AfxMessageBox("数据库连接不上! ");
if(m_pConn->State) m_pConn->Close();
return;
}
里面!

[Quote=引用 1 楼 zyq5945 的回复:]

strSQL.Format("select id,ip,port,remark,updatetime,starttime,sendnum,rcvnum,errnum,connnum,sendtra,rcvtra,clientdisc,monitorport,lowip,lownote,transferip,transfernote from serverport where id=%s",str……
[/Quote]
昨夜无风 2011-12-26
  • 打赏
  • 举报
回复
字符串要加 ''
zyq5945 2011-12-26
  • 打赏
  • 举报
回复
strSQL.Format("select id,ip,port,remark,updatetime,starttime,sendnum,rcvnum,errnum,connnum,sendtra,rcvtra,clientdisc,monitorport,lowip,lownote,transferip,transfernote from serverport where id=%s",strID);

//-->
strSQL.Format("select id,ip,port,remark,updatetime,starttime,sendnum,rcvnum,errnum,connnum,sendtra,rcvtra,clientdisc,monitorport,lowip,lownote,transferip,transfernote from serverport where id='%s'",strID);
SQL语句有错误。

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧