How to fix this error Microsoft SQL Server, Error: 126

Lefteris Rentas 20 Reputation points
2024-04-19T19:05:48.4733333+00:00

For more details. I am on windows 11 on an i7 laptop. I can connect to the (localdb)\MSSQLLocalDB through Azure Data Studio and through Visual Studio 2022 Enterprise but i can't connect through Microsoft SQL Server Management Studio. I have tried 3 versions of Microsoft SQL Server Management Studio 20.0, 19.3, 18.12. Below is the full error

TITLE: Connect to Server

------------------------------

Cannot connect to (localdb)\MSSQLLocalDB.

------------------------------

ADDITIONAL INFORMATION:

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: 56 - Unable to load the SQLUserInstance.dll from the location specified in the registry. Verify that the Local Database Runtime feature of SQL Server Express is properly installed.) (Microsoft SQL Server, Error: 126) For help, click: https://docs.microsoft.com/sql/relational-databases/errors-events/mssqlserver-126-database-engine-error

------------------------------

The specified module could not be found

------------------------------

BUTTONS:

OK

------------------------------

Lastly clicking on the link brings me to a 404

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,141 questions
0 comments No comments
{count} votes

Accepted answer
  1. MikeyQiaoMSFT-0444 3,190 Reputation points
    2024-04-22T10:01:10.16+00:00

    Hi,ΡΕΝΤΑΣ ΕΛΕΥΘΕΡΙΟΣ

    Welcome to Microsoft Q&A!

    The SQLUserInstance DLL is a link API provided by SqlLocalDB for applications, and the file is generally located at C:\Program Files\Microsoft SQL Server\150\LocalDB\Binn. The registry location is Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server Local DB\Installed Versions\15.0 (as shown in the screenshot). Please ensure the existence of the file and whether the value of the registry item InstanceAPIPath is the correct path to the file.

    User's image

    Additionally, if the above suggestion does not help with this issue, there are two other options that might fix the problem. Although you have successfully connected to LocalDB through Visual Studio, you can try repairing it using the Visual Studio Installer. Choose to click "More," Repair it.User's image

    Best regards,

    Mikey Qiao


    If the answer is helpful, please click "Accept Answer" and upvote it.


1 additional answer

Sort by: Most helpful
  1. Greg Low 1,850 Reputation points Microsoft Regional Director
    2024-04-20T03:53:56.17+00:00

    It sounds like localdb isn't started. It's important to realise that localdb doesn't run as a service like other versions of SQL Server. So VS or ADS can spin up an attached instance of localdb and talk to it, but that doesn't mean it's running as a service.

    You normally need to use the SqlLocalDB to do that: https://learn.microsoft.com/en-us/sql/tools/sqllocaldb-utility?view=sql-server-ver16

    Are you using it? Note in particular the info on "sharing" the instance of localdb.

    You can't "remotely" manage LocalDB as it doesn't open a TCP/IP connection. (I think there was a way to do that early on but it would be better to use SQL Express for that even if there was still a way to kludge it to work).

    I've created a walkthrough to show you how to start and connect from SSMS. It's here: https://blog.greglow.com/2024/04/21/sql-connecting-to-localdb-from-sql-server-management-studio-ssms/

    Also note that I've found that at times, you have to wait a few minutes after the first time you try to connect, before it will connect. (Wish it wasn't so but I imagine it's spinning itself up in the background)


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.