为何不能连接数据库?
xhe 2003-10-16 10:25:45 我加了
#include <icrsint.h>
#import "d:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
还有
if(!AfxOleInit())
{
AfxMessageBox("OLE 初始化失败!");
return false;
}
HRESULT hr;
hr = m_pConnection.CreateInstance(__uuidof(Connection));
if(FAILED(hr))
return false;
_bstr_t strConnect = "Provider=SQLOLEDB;SERVER = jdj;
DATABASE = mydb;UID = jdj;PWD = 123456";
try
{m_pConnection->Open(strConnect,"","",-1);}
catch(_com_error &e)///捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
return FALSE;
}
为何老在try里产生错误?
请高手指点一下!