|
-
November 28th, 2003, 12:50 PM
#1
SQLDMO Error Connecting
I am trying to connect to a SQL Server 2000 database using SQLDMO. The following code returns "FAILED" while it's equivalent in Visual Basic is able to connect just fine:
if FAILED(CoInitialize(NULL))
return FALSE;
LPSQLDMOSERVER2 m_pSQLServer = NULL;
HRESULT hr = CoCreateInstance(CLSID_SQLDMOServer2, NULL, CLSCTX_INPROC_SERVER, IID_ISQLDMOServer2, (LPVOID*)&m_pSQLServer);
if FAILED(hr)
return FALSE;
if (m_pSQLServer == NULL)
return FALSE;
m_pSQLServer->SetLoginTimeout(10);
hr = m_pSQLServer->SetLoginSecure(TRUE);
if FAILED(hr) return FALSE;
hr = m_pSQLServer->Connect((SQLDMO_LPCSTR)"RAY");
if FAILED(hr)
AfxMessageBox("FAILED");
else
AfxMessageBox("OK");
if (m_pSQLServer != NULL)
m_pSQLServer->Release();
CoUninitialize();
Can anyone tell me why this works in VB, but not C++?
-
November 29th, 2003, 10:44 PM
#2
Does "RAY" need to be a unicode string?
-
December 1st, 2003, 10:34 AM
#3
I don't think so. I should've mentioned that the sample that comes with SQL Server connects as follows:
if FAILED(hr = pSQLServer->Connect(TEXT(""),TEXT("sa"),TEXT("")));
and that doesn't work either.
The default for the first parameter (server name) is NULL, so
if FAILED(hr = pSQLServer->Connect();
should also work for the local server, but it doesn't.
-
December 1st, 2003, 10:51 AM
#4
Sorry, you were right. It did need to be UNICODE. It's working now. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|