Sunday, 10 August 2014

[LocalDB] Connecting to LocalDB failed [Error Code 52]

Have you been using LocalDB for your development machine and it works perfectly fine. But when you deploy your application together with LocalDB to another machine, it just failed to connect to the LocalDB.

You may see a similar error message as follows.

System.Data.SqlClient.SqlException (0x80131904): 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)

What the above message meant is that the machine you deployed does not have a Local Database Runtime installed. So before we proceed to solve the above issue, let's look through certain things.

If your localDB is created from Visual Studio 2013, then your localDB would have version 11.0. To view the version in detail, just execute the query "SELECT @@VERSION". You can execute the query through SQL Server Management Studio or Visual Studio 2013.

Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64)
    Oct 19 2012 13:38:57
    Copyright (c) Microsoft Corporation
    Express Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)

Next, we have to download the SqlLocalDB.msi from Depending on your server machine, pick 32Bit or 64Bit.

If your LocalDB version is version 12.0 or SQL Server 2014, then you may need to get the SqlLocalDB.msi from this link instead

UPDATE: With the release of SQL Server 2016, you can now get the LocalDB version 13.0 here

After you have downloaded it, install it to the machine that contains your application that is facing the above error. The installation is pretty much straightforward and remember to read the terms and condition before proceed with the installation

After you have done the installation, your application should now be able to connect to the LocalDB.

For more details :

If you do hit with another error when your web application is deployed to IIS and is accessing to LocalDB, you may want to check it out here

1 comment: