BOOL CADOConn::OnInitADOConn()
{
::CoInitialize(NULL); //初始化COM环境
try
{
m_pConnection.CreateInstance(TEXT("ADODB.Connection")); //创建连接对象实例
_bstr_t strConnect="连接语句";
m_pConnection->Open(strConnect,"","",adModeUnKnown); //连接数据库
}
catch(_com_error e) //捕获错误
{
AfxMessageBox(TEXT("连接数据库失败"));
AfxMessageBox(e.Description());
AfxMessageBox(e.ErrorMessage());
return false; //连接失败则返回false
}
return true; //连接成功则返回true
}