CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2005
    Posts
    25

    MS SQL Server database path rules

    I am using ODBC SQL Server Driver to read data into an app from a database on an MS SQL Server. The user is responsible for providing the full path and filename by selecting it themselves. The code then attaches the database to the server and opens it for reading. For testing purposes I have been using "C:\TestTest\database.mdf". If I use that path everything works correctly, however, if I use
    "C:\Test Test\database.mdf" I receive the following COM error:
    80004005
    [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database requested in login '<databasename>.mdf'. Login fails
    Unspecified error
    Microsoft OLE DB Provider for ODBC Drivers

    This is all being done in C++/MFC/COM. The user has the Microsoft SQL Server Desktop Engine 2000A on their system and we use it, along with the ODBC driver, to read information in from the provided database. In attempting to track down if the whitespace in the path is indeed the problem, or if it's something else, I have been trying to find information on what the naming convention is for database names and their full paths but have not been able to find any resources on this issue. If anyone has any URLs on such information, or any thoughts, could you please post them. thanks

  2. #2
    Join Date
    Jan 2003
    Location
    North Carolina
    Posts
    309

    Re: MS SQL Server database path rules

    Can you post a snippet of hat code section so I can understand exactly what you are doing?

  3. #3
    Join Date
    May 2005
    Posts
    25

    Re: MS SQL Server database path rules

    // Start and connect to the server
    _SQLServerPtr spSQLServer;
    spSQLServer.CreateInstance(__uuidof(SQLServer));
    spSQLServer->put_LoginSecure(FALSE)
    spSQLServer->put_ApplicationName(L"AppNameGoesHere");
    try
    {
    spSQLServer->Start(true, _T("(local)"), (_variant_t)m_ostrUserName, (_variant_t)m_ostrUserPassword);
    }
    catch(...)
    {
    // Server already started so we just need to connect
    spSQLServer->Connect(_T("(local)"), (_variant_t)m_ostrUserName, (_variant_t)m_ostrUserPassword);
    }

    spSQLServer->AttachDB(T2W(m_ostrDatabaseName), T2W(m_ostrInputFile));

    // Create the database connection string
    CString strConnection = _T("Driver={SQL Server};");
    strConnection += _T("Server=(local);");
    strConnection += _T("Database=") + ostrFileName + _T(";");
    strConnection += _T("Uid=") + m_ostrUserName + _T(";");
    strConnection += _T("Pwd=") + m_ostrUserPassword + _T(";");
    CComBSTR bstrConnection = ostrConnection;

    ado::_ConnectionPtr spConnection;
    spConnection.CreateInstance(__uuidof(ado::Connection));
    try
    {
    hr = spConnection->Open((_bstr_t)bstrConnection, L"", L"", ado::adConnectUnspecified);
    }
    catch(_com_error& error)
    {
    CString strErrMsg;
    CString strTemp;

    strErrMsg.Format(_T("\t%s\n"), error.ErrorMessage());
    strTemp.Format(_T("\n\tCode: %08lx"), error.Error());
    strErrMsg += ostrTemp;
    strErrMsg += _T("\n\tDescription: ") + error.Description();
    strErrMsg += _T("\n\tSource: ") + error.Source();
    }



    I have ommited a ton of validation and a bit of code but this is the general drift of it. The error that is occuring when white space is in the path is with the spConnection->Open method call in the last try/catch statement.

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