ADO 连接m_pConnection->Open(。。。)出现问题,请帮忙!

xsquan78 2003-10-21 11:09:24
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
if (SUCCEEDED(hr)){
hr = m_pConnection->Open
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=f:\xsq-vc\student.mdb","","",adModeUnknown);///
}}
编译的时候出现 error C2153: hex constants must have at least one hex digit
不知道如何解决,请帮忙!
...全文
369 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rechardfeng 2003-10-22
  • 打赏
  • 举报
回复
大家给我看看这段代码有问题吗?

此函数每2分钟调用一次,运行10小时后出现“内存分配访问无效”错误
int getAccountids(const char *pszFileName)
{
FILE* pRecordFile File = fopen(pszFileName, "w");

if (pRecordFile File != NULL)
{
_bstr_t bstrConnectionString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
bstrConnectionString += "test.mdb";
bstrConnectionString += ";Persist Security Info=False";

_bstr_t bstrUserID;
_bstr_t bstrPassword;

::CoInitialize(NULL);

try
{
_ConnectionPtr AdoConnection;
_RecordsetPtr AdoTable;

_com_util::CheckError(AdoConnection.CreateInstance(__uuidof(Connection)));

//下面为错误地点,出现异常
AdoConnection->Open(bstrConnectionString, bstrUserID, bstrPassword, -1);
//

try
{
_com_util::CheckError(AdoTable.CreateInstance(__uuidof(Recordset)));

AdoTable->PutRefActiveConnection(AdoConnection);

_bstr_t bstrSql;

AdoTable->Open("t_account", vtMissing, adOpenDynamic, adLockOptimistic, -1);

while (!AdoTable->adoEOF)
{
_variant_t vValue = AdoTable->Fields->Item["accountid"]->Value;

char szValue[256] = "";

szValue[0] = 0;
if (vValue.vt != VT_NULL)
{
strncpy(szValue, (_bstr_t)vValue, sizeof(szValue) -1);
}

fprintf(pRecordFile, "accountid = \"%s\"\n", szValue);

AdoTable->MoveNext();
}

AdoTable->Close();
}
catch(_com_error &e)
{
}
catch(...)
{
}

AdoConnection->Close();
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bs = _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ") + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ") + _bstr_t(e.Description());

}
catch(...)
{
}

fclose(pRecordFile);

::CoUninitialize();
}

return (0);
}
xsquan78 2003-10-21
  • 打赏
  • 举报
回复
不好意思,好像是路径搞错了应该是f:\\
这样就没有错误了。
sony19791015 2003-10-21
  • 打赏
  • 举报
回复
不是吧,哈哈,恭喜
其实许多错误都是这样的,不小心犯下的错
SPliujun 2003-10-21
  • 打赏
  • 举报
回复
对我也是刚刚学的是F:\\xsq-vc\\student.mdb
bluebohe 2003-10-21
  • 打赏
  • 举报
回复
呵呵,
恭喜,
接分

4,011

社区成员

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

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