我正在尝试通过C ++和ADO连接到同一域中不同计算机上的SQL Server 2008实例。我能够通过SQL Server Management Studio成功连接。但是通过传递相同的凭据,在我的C ++程序中,我收到错误:"用户登录失败' DOMAIN \ MyUserID'。"这是我尝试的代码:
HRESULT hr = -1;
CoInitialize(NULL);
try
{
_ConnectionPtr pConn1("ADODB.Connection");
_CommandPtr pCmd1("ADODB.Command");
hr = pConn1.CreateInstance("ADODB.Connection");
pConn1->Provider = "sqloledb";
hr = pConn1->Open("Data Source='DATAXXX';Initial Catalog='DATA123';Integrated Security=SSPI", "XX", "xyz123", adConnectUnspecified);
//hr value returned is : S_OK
}
catch (_com_error& ex) //ex value is: DB_SEC_E_AUTH_FAILED Authentication failed
{
CString err = ex.Description();
AfxMessageBox(err); //err = Login failed for user 'DOMAIN\\MyUserID'
}
if (hr != S_OK)
{
AfxMessageBox("ERROR: Opening Database connection");
return;
}
pCmd1->ActiveConnection = pConn1;
请告诉我这里我做错了什么。我的操作系统是Windows 8,我使用的是VS2013