CDatabase m_db; //数据源
CRecordset m_rs(&m_db); //记录集
CString ConnStr; //连接字符串
CString ChkStr; //查询字符串ConnStr="DSN=aaaa;Uid=;Pwd=;";
ConnStr="Select * from CK_Temp";m_db.OpenEx(ConnStr,CDatabase::openReadOnly|CDatabase::noOdbcDialog);
// ↑ 这句报错
if (!m_db.IsOpen())
{
AfxMessageBox("数据库打开错误。");
return 0;
}报错如下:
_CRTIMP void * __cdecl _malloc_dbg (
size_t nSize,
int nBlockUse,
const char * szFileName,
int nLine
)
{
void *res = _nh_malloc_dbg(nSize, _newmode, nBlockUse, szFileName, nLine);
RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));
return res;
}
CRecordset m_rs(&m_db); //记录集
CString ConnStr; //连接字符串
CString ChkStr; //查询字符串ConnStr="DSN=aaaa;Uid=;Pwd=;";
ConnStr="Select * from CK_Temp";m_db.OpenEx(ConnStr,CDatabase::openReadOnly|CDatabase::noOdbcDialog);
// ↑ 这句报错
if (!m_db.IsOpen())
{
AfxMessageBox("数据库打开错误。");
return 0;
}报错如下:
_CRTIMP void * __cdecl _malloc_dbg (
size_t nSize,
int nBlockUse,
const char * szFileName,
int nLine
)
{
void *res = _nh_malloc_dbg(nSize, _newmode, nBlockUse, szFileName, nLine);
RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));
return res;
}
try
{
m_db.OpenEx(...
}
catch(CDBException ...
{
...
}
把异常返回的字符串显示出来看是什么错误
CoInitialize(NULL);
pConnectionSource.CreateInstance(__uuidof(Connection));
rsSource.CreateInstance(__uuidof(Recordset));
pConnectionDest.CreateInstance(__uuidof(Connection));
rsDest.CreateInstance(__uuidof(Recordset));
ConnStr="Select * from CK_Temp";这个变量你赋了两遍值。
调试了几个小时,发现真正原因是不小心把“#include <afxdb.h>”删除了!
发现后晕了半天。