SQL Server LocalDB 2014 Connection String

I always face issues for LocalDB connection string when download GitHub code developed using SQL Express 2012 – LocalDB.

I assumed that I could just update my connection string from v11.0 to v12.0 but it seems that Microsoft have changed the naming scheme for this version. Now the automatic instance is named MSSQLLocalDB.

So, For SQL Server 2012 LocalDB, I had this connection string:

  <add name="DefaultConnection"
   connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Test.mdf;Initial Catalog=Test;Integrated Security=True"
providerName="System.Data.SqlClient" />

For SQL Server 2014 LocalDB the connection string should be:

 <add name="DefaultConnection"
  connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Test.mdf;Initial Catalog=Test;Integrated Security=True"
providerName="System.Data.SqlClient" />

You also need to update, Entity Framework default connection factory setting in web.config file where v11.0 should be v12.0 for SQL Server 2014 LocalDB.

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameter value="v12.0" />

Hope this will help 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s