void CDlgLogin::OnOK()
{
// TODO: Add extra validation here
this->UpdateData(TRUE);
HRESULT hr;
_ConnectionPtr pConn; //声明ADO Connection对象实例
_CommandPtr pCommand; //声明ADO Command 对象实例
try
{
//创建Connection对象
pConn.CreateInstance("ADODB.Recordset");
//设置连接字符串,必须是BSTR型或者_bstr_t类型
_bstr_t strConnect="Provider=SQLOLEDB;Server=FA9E17D4F84D4FB;Database=ShopAssistant;UID=sa;PWD=sa;";
hr=pConn->Open("Data Source=ShopAssistant;UID=sa;PWD=sa;","","",adModeUnknown);
}
catch(_com_error& ex)
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",ex.ErrorMessage());
AfxMessageBox(errormessage);//显示错误信息
}
编译以上代码时,提示指针失效,无法连接,数据源已经配置好,可是无法连接数据库,请高手帮帮忙哦!!先谢谢了!