关于连接数据库的问题
程序连接数据库时一直连接不上,求大神帮忙。
代码如下
try{
_ConnectionPtr pConnection = NULL;
pConnection.CreateInstance(_uuidof(Connection));
pConnection->Mode = adModeUnknown;
pConnection->ConnectionTimeout = 5;
pConnection->CommandTimeout = 5;
pConnection->ConnectionString = _T("sever=.\SQLEXPRESS;Provider=SQLOLEDB;Initial Catalog=pcTest; User ID = sa; Password = 960823zsq");
HRESULT hr = pConnection->Open("","","",adConnectUnspecified);
if (SUCCEEDED(hr)){
AfxMessageBox(TEXT("连接成功!"));
}
}
catch (_com_error &e){
AfxMessageBox(e.ErrorMessage());
}
是字符串问题还是什么,端口什么的能开都开了。数据库的账户密码也都没有问题。