SQL数据库连接问题...
代码如下:
m_pConnection.CreateInstance("ADODB.Connection");
CString strCn;
strCn.Empty();
strCn="provider=SQLOLEDB;data source="+this->DataSource
+";DATABASE="+this->Catalog
+";userID="+this->UserID
+";Password="+this->Password;
_variant_t bcnstr=_variant_t(strCn);
_variant_t bunstr=_variant_t(this->UserID);
_variant_t bpwdstr=_variant_t(this->Password);
//打开一个连接
try
{
m_pConnection->Open(_bstr_t(bcnstr),_bstr_t(bunstr),
_bstr_t(bpwdstr),-1);//adOpenUnspecified
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Warning: 连接数据库发生异常. 错误信息: %s; 文件: %s; 行: %d ", e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(errormessage);
return FALSE;
}
catch(...)
{
AfxMessageBox("Warning :连接数据库时发生未知错误");
return FALSE;
}
return TRUE;
为什么运行是总是连接不上.啊..各位帮帮忙啊.