vc写的测试数据库连接
源代码在线查看: 测试数据库连接.txt
测试数据库连接
_ConnectionPtr m_pConnection;
m_pConnection=NULL;
if(!oleinit)
{
try
{
if (!AfxOleInit())
{
//AfxMessageBox("ole 初始化错误");
return false;
}
}
catch(...)
{}
}
oleinit=true;
m_pConnection.CreateInstance(__uuidof(Connection));
// CString dbPath=m_AppPath+"\\DATABASE\\DB_P.mdb";
m_strConnection = _T("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=ahryDB;Data Source=LH”);
try
{
//打开本地Access库DZBL边坡数据库.mdb,可以做成活得
m_pConnection->Open((LPCTSTR)m_strConnection,
"","",adModeUnknown);
}
catch(_com_error e)
{
//AfxMessageBox("数据库连接失败,请确认数据库‘DB_P.mdb’路径!");
return false;
}
m_pConnection=NULL;
return true;