locked
Can't Connect to LocalDB Database - Using SQL Server Express 2016 RRS feed

  • Question

  • I have a Windows Form project in VS2015 that uses a local database file (.MDF).
    The code has been working for some time, but recently I was having a problem restoring from a backup file. I decided to uninstall SQL Server (different versions) and do a fresh install of SQL Server Express 2016 SP2 (Advanced version).

    The install went okay and I did include LocalDB which is needed to connect local .MDF database files. Under 'Programs and Features' I can see several Microsoft SQL Server 2016 items, including LocalDB.

    Now, for some reason I cannot connect to the local database. In VS, in Server Explorer, I try to add the .MDF file to 'Data Connections'. In the 'Add Connection' dialog I select 'Microsoft SQL Server Database File' as the source. Then I browse to and select the .MDF file. I use Windows Authentication (which I choose during SQL Server install). Clicking on 'Test Connection' produces the following error:

    " A network-related or instance-specific error occurred while
    establishing a connection to SQL-Server. The server was not
    found or was not accessible. Verify that the instance name
    is correct and that SQL Server is configured to allow remote
    connections. (provider: SQL Network Interfaces, error: 0-
    [x89C501181]) "

    I believe the problem is something with SQL Server installation because the installed version of my project also cannot connect to the database. Could it be a Windows Registry issue?

    Would very much appreciate help.
    Thursday, June 25, 2020 9:54 PM

All replies

  • Hi ArcherVic,

    Could you please check if you could connect to the Local DB by SSMS? You can get SSMS from here. If it is not work ,what is the error message that you got.  

    >>" A network-related or instance-specific error occurred while establishing a connection to SQL-Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 0-[x89C501181]) "

    Did you run the VS as administrator? Right click VS > More > Run as administrator

    Did you choose the right data source for the mdf in advance properties as below screenshot?

    You can also follow below blogs to troubleshot SQL  server connection issue.
    Troubleshoot connecting to the SQL Server Database Engine
    Resolving could not open a connection to SQL Server errors

    If you can connect to SQL server Local DB by SSMS, may be the issue is related to VS, you can open  a new thread at the VS  forum to get better help

    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

    Friday, June 26, 2020 2:50 AM
  • Cathy, thanks for responding.

    Yes I can connect to the .MDF local DB using SSMS.

    I ran SQL Server 2016 Configuration Manager and got this  (for some reason I can't post images here)

    SQL Server (SQLEXPRESS)     State: Running 

    All is running except SQL Server Agent, and SQL Server Browser.

    I tried changing the Data Source as you suggested. There were two choices: (LocalDB)\MSSQLLocalDB and .\SQLEXPRESS

    I selected .\SQLEXPRESS , but got the following error -

    "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance...."

    (when I try to post images here, I get the message that my account has to be verified. Please help me with that, otherwise it's very difficult to communicate).

    Friday, June 26, 2020 5:14 PM
  • Hi ArcherVic,

    >> (when I try to post images here, I get the message that my account has to be verified. Please help me with that, otherwise it's very difficult to communicate).

    You can let your account verified by posting on Verify Account 43.

    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

    Monday, June 29, 2020 9:51 AM
  • Thank you Cathy,

    I did the request. Now back to the original question. I discovered the problem is that the default  instance of LocalDB (name = MSSQLLocalDB) is set to version 12.0 (SQL Server 2014), and I need it to be version 13.0 (SQL Server 2016).

    I tried using the command line utility SqlLocalDB.exe in the directory C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn  to first delete, then create the instance, but just got error codes as follows.

    C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn>SQLLocalDB delete "MSSQLLocalDB"
    FormatMessageW failed. Error code returned: 15100

    C:\Program Files\Microsoft SQL Server\130\LocalDB\Binn>SQLLocalDB create "MSSQLLocalDB"
    FormatMessageW failed. Error code returned: 15100

    How can I set the default instance of LocalDB to version 13? Thanks for helping.

    Tuesday, June 30, 2020 12:57 AM
  • I went into "Programs and Features" and selected Sql Server 2016 LocalDB and did a "Repair". That seems to have fixed it. Wish I understood why.

    Vic

    Wednesday, July 1, 2020 12:59 PM