none
LocalDB cannot attach database RRS feed

  • Question

  • Using Native Client 11.0 ODBC Driver, trying to programatically attach a database "DB A" to a LocalDB instance leads to an attempt to attach a different "DB B", resulting in the following error (shown on the ODBC trace log):

    DIAG [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'xxx\xxxxxxx'. (18456) 

    DIAG [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "Database B" requested by the login. The login failed. (4060) 

    DIAG [01S00] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0) 

    Seems to be that previous connection through ODBC is being cached somewhere.

    Have tried:

    1. Restarted computer

    2. Deleting LocalDB instance folder AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances 

    3. Complete Re-install of localdb

    Neither works, would there be any other places where ODBC is caching connection instances?

    More from the ODBC trace:

    50ec-5264 ENTER SQLAllocHandle 
    SQLSMALLINT     1 <SQL_HANDLE_ENV>
    SQLHANDLE       0x0000000000000000
    SQLHANDLE *     0x000000001126F388

    50ec-5264 EXIT  SQLAllocHandle  with return code 0 (SQL_SUCCESS)
    SQLSMALLINT     1 <SQL_HANDLE_ENV>
    SQLHANDLE       0x0000000000000000
    SQLHANDLE *     0x000000001126F388 ( 0x000000002DF90D40)

    50ec-5264 ENTER SQLSetEnvAttr 
    SQLHENV         0x000000002DF90D40
    SQLINTEGER      200 <SQL_ATTR_ODBC_VERSION>
    SQLPOINTER      3 <SQL_OV_ODBC3>
    SQLINTEGER      -6 

    50ec-5264 EXIT  SQLSetEnvAttr  with return code 0 (SQL_SUCCESS)
    SQLHENV         0x000000002DF90D40
    SQLINTEGER      200 <SQL_ATTR_ODBC_VERSION>
    SQLPOINTER      3 <SQL_OV_ODBC3>
    SQLINTEGER      -6 

    50ec-5264 ENTER SQLSetEnvAttr 
    SQLHENV         0x000000002DF90D40
    SQLINTEGER      201 <SQL_ATTR_CONNECTION_POOLING>
    SQLPOINTER      2 <SQL_CP_ONE_PER_HENV>
    SQLINTEGER      -6 

    50ec-5264 EXIT  SQLSetEnvAttr  with return code 0 (SQL_SUCCESS)
    SQLHENV         0x000000002DF90D40
    SQLINTEGER      201 <SQL_ATTR_CONNECTION_POOLING>
    SQLPOINTER      2 <SQL_CP_ONE_PER_HENV>
    SQLINTEGER      -6 

    50ec-5264 ENTER SQLAllocHandle 
    SQLSMALLINT     2 <SQL_HANDLE_DBC>
    SQLHANDLE       0x000000002DF90D40
    SQLHANDLE *     0x000000001126F430

    50ec-5264 EXIT  SQLAllocHandle  with return code 0 (SQL_SUCCESS)
    SQLSMALLINT     2 <SQL_HANDLE_DBC>
    SQLHANDLE       0x000000002DF90D40
    SQLHANDLE *     0x000000001126F430 ( 0x000000002DF90E20)

    50ec-5264 ENTER SQLSetConnectAttrW 
    SQLHDBC         0x000000002DF90E20
    SQLINTEGER      103 <SQL_ATTR_LOGIN_TIMEOUT>
    SQLPOINTER      0
    SQLINTEGER      -5 

    50ec-5264 EXIT  SQLSetConnectAttrW  with return code 0 (SQL_SUCCESS)
    SQLHDBC         0x000000002DF90E20
    SQLINTEGER      103 <SQL_ATTR_LOGIN_TIMEOUT>
    SQLPOINTER      0
    SQLINTEGER      -5 

    50ec-5264 ENTER SQLDriverConnectW 
    HDBC            0x000000002DF90E20
    HWND            0x0000000000000000
    WCHAR *         0x00007FFB794121C0 [      -3] "******\ 0"
    SWORD           -3 
    WCHAR *         0x00007FFB794121C0 
    SWORD           -3 
    SWORD *         0x0000000000000000
    UWORD           0 <SQL_DRIVER_NOPROMPT>

    50ec-5264 EXIT  SQLDriverConnectW  with return code -1 (SQL_ERROR)
    HDBC                0x000000002DF90E20
    HWND                0x0000000000000000
    WCHAR *             0x00007FFB794121C0 [      -3] "******\ 0"
    SWORD               -3 
    WCHAR *             0x00007FFB794121C0 
    SWORD               -3 
    SWORD *             0x0000000000000000
    UWORD               0 <SQL_DRIVER_NOPROMPT>

    DIAG [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'xxx\xxxxxxx'. (18456) 

    DIAG [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "Other Database" requested by the login. The login failed. (4060) 

    DIAG [01S00] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0) 

    DIAG [28000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'xxx\xxxxxxx'. (18456) 

    DIAG [42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "Other Database" requested by the login. The login failed. (4060) 

    DIAG [01S00] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0) 


    Tuesday, November 5, 2019 6:17 PM

All replies

  • Hi _RonP,

    Did you check the login account that you are using for Local DB from SSMS? Did the login has the permission to read and write the folder?  Did you try to attach a database from SSMS? What error message that you can get from SQL server Local DB error log? 

    Best regards,
    Cathy 

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to  MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, November 6, 2019 6:37 AM
  • Invalid connection string attribute (0) 

    And how does your connection string look like?

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, November 6, 2019 7:50 AM
  • Hi Cathy, user permissions is setup correctly.

    To answer your second question, the workaround is that once we have attached the actual database or any database with the same name from SSMS, issue does not appear.

    I didn't get a chance to get the SQL server Local DB error log, but I recall seeing trace that the database "DB A" can't be located. But it shouldn't look for "DB A" in the first place.


    Wednesday, November 6, 2019 7:00 PM
  • ODBC;DATABASE={0};DSN={1};Initial Catalog=master;Integrated Security=True

    Wednesday, November 6, 2019 7:03 PM