在本机上能够连接上,但是将Release版本放到其他机子上就连接不上Demo.mdb了  怎么回事 
 连接数据库的代码如下:LRESULT CDataComm::OpenAcessConnection()
{
CTest32App *pApp = (CTest32App*)AfxGetApp(); try 

m_pConnection.CreateInstance("ADODB.Connection");
// 打开本地Access库DB_ZWSB.mdb
CString sDS;

sDS.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%sDemo.mdb;Persist Security Info=False",pApp->GetAppPath());

m_pConnection->Open(_bstr_t(sDS),"","",adModeUnknown);
}
catch(_com_error &e)
{
AfxMessageBox("数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
AfxMessageBox(e.ErrorMessage());
//delete pApp;
return 1;
}
//delete pApp;
return 0;
}

解决方案 »

  1.   

    catch(_com_error &e)
    {
    AfxMessageBox("数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
    AfxMessageBox(e.ErrorMessage());
    AfxMessageBox(e.Description());
    //delete pApp;
    return 1;
    }
      

  2.   

    提示这个错误:-》
    数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
      

  3.   

    ;Data Source=%sDemo.mdb你直接指定Demo.mdb的绝对路径试试
      

  4.   

    接下来的两个错误提示报什么。
    AfxMessageBox(e.ErrorMessage());
    AfxMessageBox(e.Description());
      

  5.   

    King_hhuang
    绝对路径试了 没用。zyq5945
    未知的指针exe和mdb都一起打包去了
    Release版本放到其他机子上就连接不上Demo.mdb ,在本机上可以
      

  6.   

    有一点,你看看你建的Demo.mdb用的ACCESS是什么版本的,是不是07的?换成03版本的
      

  7.   

    yan69412
      03 的  自己建的  数据库也能打开啊 
      

  8.   

    这又一个例子
    你可以参考一下
    http://blog.csdn.net/xianglitian/article/details/5617173
      

  9.   

    zyq5945   xianglitian 
    bool CDBAdo::SetConnectionString(CString strDriver, CString strDataSrc, CString strPassword)  
    {  
        CString strProvider, strDataSource, strPWD;  
      
        strProvider.Format(_T("Provider=%s;"), strProvider);  
        strPWD.Format(_T("Password=%s;"), strPassword);  
        strUID.Format(_T("User ID=%s;"), strUserID);  
        strData.Format(_T("=%s;"), strCatalog);  
        strDataSrc.Format(_T("Data Source=%s,%ld;"), strIP, wPort);  
      
        //构造连接字符串   
        m_strConnect    = strProvider+strPWD+_T("Persist Security Info=True;")+strUID+strData+strDataSrc;  
      
            return true;  
    }  代码中strProvider 应该传什么值?Initial Catalog呢
      

  10.   

    我提供的例子里也能看到啊
    m_dbDemo.SetConnectionString(_T("Microsoft.Jet.OLEDB.4.0"), _T("Demo.mdb"), _T("123456"));
    你有什么问题呢
      

  11.   

    Demo.mdb将这个数据库复制到程序目录下,然后把前面的%s删掉
      

  12.   

    对方的电脑上没有安装Microsoft.Jet.OLEDB.4.0
      

  13.   

    http://download.csdn.net/source/3530532
      

  14.   

    这个要把Demo.mdb文件拷到程序的存放目录下就行了。或者你再看看程序的存放目录下有没有msado15.tli和msado15.tlh这两个文件,如果没有,也需要拷到目录下。你试试看,我之前就是这么做的,然后成功了。
      

  15.   

    http://vckbase.com/document/viewdoc/?id=1274