m_pRecordset关闭后程序崩溃

yangyanzhao 2018-01-11 04:11:17
0x011272EE 处有未经处理的异常(在 PiggyIOCPServer.exe 中):  0xC0000005:  读取位置 0x6A4A5754 时发生访问冲突。
m_pRecordset->Open((_bstr_t)strTemp1, m_pConnection.GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText);
int recordCount = 0;
recordCount = m_pRecordset->GetRecordCount();
string intStr;
if (recordCount > 0){
m_pRecordset->MoveFirst();///移到首条记录
}

for (int i = 0; i < recordCount; i++){
_variant_t vtName, vtLabel, vtRawMin, vtRawMax, vtEngMin, vtRangeEngMax;
vtName = m_pRecordset->GetCollect("name");
vtLabel = m_pRecordset->GetCollect("label");
vtRawMin = m_pRecordset->GetCollect("rawMin");
vtRawMax = m_pRecordset->GetCollect("rawMax");
vtEngMin = m_pRecordset->GetCollect("engMin");
vtRangeEngMax = m_pRecordset->GetCollect("engMax");

//memset((char*)info[i]->field.c_str(), 0, sizeof(info[i]->field));
info[i]->name = (char*)(_bstr_t)vtName;
info[i]->label = (char*)(_bstr_t)vtLabel;
info[i]->rawMin = atoi((char*)(_bstr_t)vtRawMin);
info[i]->rawMax = atoi((char*)(_bstr_t)vtRawMax);
info[i]->engMin = atoi((char*)(_bstr_t)vtEngMin);
info[i]->engMax = atoi((char*)(_bstr_t)vtRangeEngMax);

dataInfos.push_back(info[i]);

//插入到界面
m_ctlListDataEnable.InsertItem(i, info[i]->name.c_str());
m_ctlListDataEnable.SetItemText(i, 1, info[i]->label.c_str());

itoa(info[i]->rawMin, (char*)intStr.c_str(), 10);
m_ctlListDataEnable.SetItemText(i, 2, intStr.c_str());
itoa(info[i]->rawMax, (char*)intStr.c_str(), 10);
m_ctlListDataEnable.SetItemText(i, 3, intStr.c_str());
itoa(info[i]->engMin, (char*)intStr.c_str(), 10);
m_ctlListDataEnable.SetItemText(i, 4, intStr.c_str());
itoa(info[i]->engMax, (char*)intStr.c_str(), 10);
m_ctlListDataEnable.SetItemText(i, 5, intStr.c_str());

m_pRecordset->MoveNext();
}
m_pRecordset->Close();
加载,插入,删除都没有问题,数据进数据库的,就是数据集关闭后抛出异常
...全文
653 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgl7903 2018-01-13
  • 打赏
  • 举报
回复
VS 调试菜单 异常中打开 Win32 CXXXX5 异常, 调试运行, 遇CXXX5时,会停在代码处, 结合调用堆栈 修改代码解决之
worldy 2018-01-12
  • 打赏
  • 举报
回复
看起来只是从记录集里读数据,没有对m_pRecordset的操作,应该不会出现异常,你将 m_pRecordset->Open到m_pRecordset->Close();之间的代码备注掉试试 (只保留open,然后close)
oyljerry 2018-01-11
  • 打赏
  • 举报
回复
m_pRecordset应该已经是一个非法指针了。是不是被其他地方释放了

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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