我的程序在自己的机器上编译运行没问题,可是静态编译后在其他机器上就会出问题,我通过用异常查找问题 发现是在 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复制过去了 
还请大家帮忙看看,如果我上面有什么地方说的不清楚,还请指出~

解决方案 »

  1.   

    上面是我发现的情况  大家帮忙提提解决方向或使用ADO程序需要注意的地方等待结果~~~
      

  2.   

    连接字符串对吗?
    建议这样写
    CString sql="Delete From Test where num=3"  ;
    _RecordsetPtr m_pRs;
    _ConnectionPtr m_pCon;
    m_pRs=m_pCon->Execute((_bstr_t)sql,NULL,NULL);
      

  3.   

    请问,在stafx.cpp中你加了struct InitOle
    {
    InitOle()
    {
    ::CoInitialize(NULL);
    } ~InitOle()
    {
    ::CoUninitialize();
    }
    }_init_InitOle;这个了没?
      

  4.   

    試試看這個_variant_t vChangeRecord;
    m_pCommand->Execute(&vChangeRecord,NULL,adCmdText);
      

  5.   

    to : ronk(ARCHER)
    我在APP中已经初始化过OLE库了
    if(!AfxOleInit())
    {
        AfxMessageBox("OLE初始化失败!");
        return FALSE;
    }to:wei_x1980(大嘴)
    不行   依然是那个问题
      

  6.   

    我之前用CommandPtr调用存储过程也出现过类似的问题....第一次调用成功,第二次调用失败....但是后来也是照上面的写法重新写了一次,就没问题了....奇怪了....
      

  7.   

    用try{   execute} catch (_com_error e){AfxMessageBox(e.description();看失败的原因,