ADO字符串直接用udl文件可以连接,用字符串不行。
字符串在ADO助手上就可以使用,在程序里就不可以,会抛出异常,我用的是VS2013是否和编译器有关系。代码:
_ConnectionPtr pConnection = NULL;
pConnection.CreateInstance(__uuidof(Connection));
pConnection->Mode = adModeUnknown;
pConnection->ConnectionTimeout = 5;
pConnection->CommandTimeout = 5;
pConnection->ConnectionString = _T("Provider=SQLOLEDB.1;Password=960823zsq;Persist Security Info=True;User ID=sa;Initial Catalog=Test;Data Source=KXG1WMOGDQS7DHE\ZSQ960823");
HRESULT hr = pConnection->Open("", _bstr_t(_T("sa")), _bstr_t(_T("960823zsq")), adOpenUnspecified);
if (FALSE(hr)){
AfxMessageBox(TEXT("数据库连接失败!"));
return;
}