CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2000
    Posts
    66

    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++?

  2. #2
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    Does "RAY" need to be a unicode string?

  3. #3
    Join Date
    Mar 2000
    Posts
    66
    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.

  4. #4
    Join Date
    Mar 2000
    Posts
    66
    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
  •  





Click Here to Expand Forum to Full Width

Featured