SQL Server Ado Connection fails
I cannot seem to get my application to connect with my SQL Server. I am constantly getting the error message "Login Failed for user Administator". I am not specifying a longin name or a password. I just installed the SQL Server 7.0 developer edition. I created a new Database. It created a default server on installation, and has 2 logins (That I did not create!) 1/ Administator 2/ sa. I don't know the password for either of the logins since I did not create them. I installed SQL Server on my machine which has Windows NT and is connected to a network. I think it may have taken administrator from there.
Anyway, here is the code I tried, any help that could be provided please do:
BOOL CSchedulerDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
HRESULT hr;
CString strConn = "Provider=sqloledb;server=comp_acer9;database=Project_Data.mdf";
//make connection
try{
hr = m_pConnection.CreateInstance(__uuidof(Connection));
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open(_bstr_t(strConn), _bstr_t(L""), _bstr_t(L""), adModeUnknown);
if(SUCCEEDED(hr))
{
m_bIsConnectionOpen = TRUE;
}
}
}
catch(_com_error &e)
{
_bstr_t bstrError = e.Error();
_bstr_t bstrDesc = e.Description();
TRACE(bstrError); //returns -2147217843(1)
TRACE(bstrDesc); //returns "Login Failed for user 'Administrator'."(1)
}
catch(...)
{
}
return TRUE;
}
Thanks in advance!
Mike B
Re: SQL Server Ado Connection fails
1) you should specify User ID and Password values in your connection string
2) use your database without mdf extension
If it helps you let me know.
Bayram.
Re: SQL Server Ado Connection fails
the sa account is originaly not been provides with a Password you can set it yourself
Jo Van Vosselen