ADO连接数据库问题,总出现“无效指针”错误
BOOL CSqlDlg::Init()
{
CString m_strPath;
CString m_strJDCFile;
CString m_strJDC;
CoInitialize(NULL); //对连接进行初始化
// m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection.CreateInstance("ADODB.Connection");
try
{
//AfxMessageBox(cJDC);
m_pConnection->Open((LPCTSTR)"Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=JDC;Data Source=BR51XI7JYQMJPTS",(LPCTSTR)(""),(LPCTSTR)(""),adConnectUnspecified);
}
catch(_com_error e) //捕捉异常
{
CString strError;
strError.Format( e.ErrorMessage( ) );
//显示错误信息 "无效指针"
AfxMessageBox(strError);
return FALSE;
}
m_pRecordset.CreateInstance("ADODB.Recordset");
return TRUE;
}