在本机上能够连接上,但是将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;
}
连接数据库的代码如下: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;
}
{
AfxMessageBox("数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
AfxMessageBox(e.ErrorMessage());
AfxMessageBox(e.Description());
//delete pApp;
return 1;
}
数据库连接失败,确认数据库Demo.mdb是否在当前路径下!");
AfxMessageBox(e.ErrorMessage());
AfxMessageBox(e.Description());
绝对路径试了 没用。zyq5945
未知的指针exe和mdb都一起打包去了
Release版本放到其他机子上就连接不上Demo.mdb ,在本机上可以
03 的 自己建的 数据库也能打开啊
你可以参考一下
http://blog.csdn.net/xianglitian/article/details/5617173
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呢
m_dbDemo.SetConnectionString(_T("Microsoft.Jet.OLEDB.4.0"), _T("Demo.mdb"), _T("123456"));
你有什么问题呢