连接数据库,在自己机子上面一切正常(win7,vs2010下调试,ACCESS2007)。换其他电脑(安装ACCESS2007,xp系统),连接提示连接失败,无效指针,应该是在
m_pConnection->Open(strConnect,"","",adModeUnknown);这句出错了,但具体应该是什么错误,该怎么改,忘大神指导呀!
以下是代码!
int AdoAccess::OnInitADOConn() //连接数据库
{
::CoInitialize(NULL);
//::AfxOleInit();
try
{
m_pConnection.CreateInstance("ADODB.Connection");
//AfxMessageBox(_T("连接1"));
_bstr_t strConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=order.accdb;Persist Security Info=False;";
//AfxMessageBox(strConnect);
m_pConnection->Open(strConnect,"","",adModeUnknown); //AfxMessageBox(_T("连接3"));
// printf("连接数据库成功\n");
}
catch (_com_error e)
{
//printf("连接数据库失败\n");
AfxMessageBox(_T("连接失败"));
AfxMessageBox(e.ErrorMessage());
return 1;
} return 0;
}
m_pConnection->Open(strConnect,"","",adModeUnknown);这句出错了,但具体应该是什么错误,该怎么改,忘大神指导呀!
以下是代码!
int AdoAccess::OnInitADOConn() //连接数据库
{
::CoInitialize(NULL);
//::AfxOleInit();
try
{
m_pConnection.CreateInstance("ADODB.Connection");
//AfxMessageBox(_T("连接1"));
_bstr_t strConnect = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=order.accdb;Persist Security Info=False;";
//AfxMessageBox(strConnect);
m_pConnection->Open(strConnect,"","",adModeUnknown); //AfxMessageBox(_T("连接3"));
// printf("连接数据库成功\n");
}
catch (_com_error e)
{
//printf("连接数据库失败\n");
AfxMessageBox(_T("连接失败"));
AfxMessageBox(e.ErrorMessage());
return 1;
} return 0;
}
解决方案 »
- Debug Assertion Failed! CBitmapView::OnPaint() line 67
- 监视剪贴板的问题,搞了一晚上还没好,请教!
- 初学vc:请帮我看看这两个语句怎么改?
- 请教一个SDK下简单的问题!!
- 请教高人:如何实现一个自己的CRectTracker,或如何实现拖动时的虚边框效果?
- 怎么添加多列到datagrid控件中?好象只能使用默认的两列……
- 菜鸟问题:如何得到当前程序的路径?
- user breakpoint called from[vetor<CString>传值调用的问题]
- MFC Tab Control 中我在主页点击修改按钮,如何更改标签页的lListcontrol 为啥一直是错误 afwin2.inl line:
- 界面超漂亮的桌面时钟
- ADO连接打开ACCESS,catch错误返回:无效指针
- VC中新建的对话框无法显示
微软官方解释:http://support.microsoft.com/kb/2640696补丁号:KB2640696下载安装后,对于VC++程序,另需要更改头文件中的ADO连接为如下:#import "c:\Program Files\Common Files\System\ado\msado60.tlb" no_namespace rename("EOF", "adoEOF")重新编译,发布问题解决。