我最近尝试创建一个程序,可以读取 ODBC 数据库,然后使用 CRecordset 类将条目写入 Excel 文件,该程序完美编译,但问题出现在执行中......
第一个错误:
调试断言失败!
程序:C:\Windows\system32\mfc140ud.dll
文件:f:\dd ctools c7libs\ship tlmfc\include fxwin1.inl
线路:24
第二个错误:
调试断言失败!
程序:C:\Windows\system32\mfc140ud.dll
文件:f:\dd ctools c7libs\ship tlmfc\src\mfc\dbcore.cpp
线路:3312
这两个错误都指向mfc140ud.dll文件,它不是丢失的文件,所以不是问题。
这里是引发异常的函数:
void parseDB(CRecordset &rs, const CString &SqlString, CString strOut) {
std::cout << "test2";
rs.Open(CRecordset::snapshot, SqlString, CRecordset::readOnly);
std::string entry;
std::fstream file;
std::cout << "test3";
while(!rs.IsEOF()) {
std::cout << "test4";
rs.GetFieldValue((short)0, strOut);
CT2CA pszConvertedAnsiString = strOut;
entry = pszConvertedAnsiString;
writeXLSX(entry.c_str(), file);
rs.MoveNext();
}
rs.Close();
}
“std::cout << "test"" are here for debugging, and my program generates these errors right after the "test2" display, so I deducted that the error comes from the "Open" line.
这是我初始化CRecordset的方式:
CString sDsn;
CDatabase db;
CRecordset rs(&db);
CString strOut;
CString SqlString;
然后,我在 switch-case 中使用 CALL SQL 函数:
switch (sequence) {
case 1:
SqlString = "CALL GETCUSNAME(AGENTS)";
break;
case 2:
SqlString = "CALL GETCUSNAME(CLIENT)";
break;
default:
AfxMessageBox(_T("Wrong entry!"));
}
我在很多网站上搜索都找不到答案,这就是我在这里提问的原因,在此先感谢。
第一个断言来自
AfxGetResourceHandle
抱怨没有设置正确
这通常会发生,因为您要么没有在应用程序开始时调用
AfxWinInit
(如果您有一个控制台应用程序并且没有使用 MFC 向导设置它,很可能就是这种情况),或者您正在编写从非 MFC 代码调用的 MFC DLL,并且您没有在每个外部可见函数的开头添加AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
。
我相信第二个是因为 MFC 要求您将 CALL 查询包含在花括号中,如下所示:
{CALL GETCUSNAME(AGENTS)}
。否则无法识别该调用,并且代码执行会进入它不应该采用的路径。
我有一个类似的错误,我发现这只发生在调试版本中,因为我正在为某些桌面软件构建一个插件,并且我在这个软件中调用了我的 MFC 对话。但是,问题是该软件使用的是发行版 MFC 库 (MFC140u.dll),而我的对话调试版本使用的是 (MFC140ud.dll),我尝试将 (MFC140ud.dll) 文件放入我的项目文件并指向 vs 和加载它的软件。坚果没有用。对我有用的解决方案是在包含 MFC 标头之前添加条件编译预处理器片段以取消定义 DEBUG。如果之前定义过,则重新定义 DEBUG。在我预编译的头文件中。
#pragma once
#ifndef PCH_H
#define PCH_H
#ifdef _DEBUG
#define _DEBUG_WAS_DEFINED
#undef _DEBUG
#define NDEBUG
#endif
// -- Windows and MFC Inclusions --
#include "afxwin.h"
#include "afx.h"
#include "framework.h"
#include <Windows.h>
// -- Project Inclusions --
#include <xxxxx.h>
#if defined(_AFXEXT) && defined(__cplusplus)
#include <afxcoll.h>
#endif
#endif //PCH_H