我的程序在自己的机器上编译运行没问题,可是静态编译后在其他机器上就会出问题,我通过用异常查找问题 发现是在 m_pCommand->Execute时出现的问题 所以可以肯定是在ADO操作上出现的问题
下面是关于_CommandPtr的代码;stdafx.h #import "c:\program files\common files\system\ado\msado15.dll"no_namespace rename("EOF","adoEOF")CMyApp.h_ConnectionPtr m_pConnection;CMyApp.cppCMyApp::Initstance()
{ m_pConnection.CreateInstance("ADODB.Connection");
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=Test.mdb","","",adModeUnknown);
}CMyView.h_CommandPtr m_pCommand;CMyView.cppCMyView::CMyView() //构造函数
{
m_pCommand.CreateInstance("ADODB.Command");
}CMyView::OnTest()
{
m_pCommand->ActiveConnection = theApp.m_pConnection;
m_pCommand->CommandText = "Delete From Test where num=3"
m_pCommand->CommandType = adCmdText;
m_pCommand->CommandTimeout = 15;
m_pCommand->Execute(NULL,NULL,adCmdText); //在其他机器上,到这里就出错
}
我感觉是不是没有加载什么东西啊? 我在其他机器上运行,只是把数据库文件和静态编译的EXE复制过去了
还请大家帮忙看看,如果我上面有什么地方说的不清楚,还请指出~
下面是关于_CommandPtr的代码;stdafx.h #import "c:\program files\common files\system\ado\msado15.dll"no_namespace rename("EOF","adoEOF")CMyApp.h_ConnectionPtr m_pConnection;CMyApp.cppCMyApp::Initstance()
{ m_pConnection.CreateInstance("ADODB.Connection");
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=Test.mdb","","",adModeUnknown);
}CMyView.h_CommandPtr m_pCommand;CMyView.cppCMyView::CMyView() //构造函数
{
m_pCommand.CreateInstance("ADODB.Command");
}CMyView::OnTest()
{
m_pCommand->ActiveConnection = theApp.m_pConnection;
m_pCommand->CommandText = "Delete From Test where num=3"
m_pCommand->CommandType = adCmdText;
m_pCommand->CommandTimeout = 15;
m_pCommand->Execute(NULL,NULL,adCmdText); //在其他机器上,到这里就出错
}
我感觉是不是没有加载什么东西啊? 我在其他机器上运行,只是把数据库文件和静态编译的EXE复制过去了
还请大家帮忙看看,如果我上面有什么地方说的不清楚,还请指出~
建议这样写
CString sql="Delete From Test where num=3" ;
_RecordsetPtr m_pRs;
_ConnectionPtr m_pCon;
m_pRs=m_pCon->Execute((_bstr_t)sql,NULL,NULL);
{
InitOle()
{
::CoInitialize(NULL);
} ~InitOle()
{
::CoUninitialize();
}
}_init_InitOle;这个了没?
m_pCommand->Execute(&vChangeRecord,NULL,adCmdText);
我在APP中已经初始化过OLE库了
if(!AfxOleInit())
{
AfxMessageBox("OLE初始化失败!");
return FALSE;
}to:wei_x1980(大嘴)
不行 依然是那个问题