sql-serverconnection-stringlocaldb

Sql difference between localhost and (LocalDb)/MSSQLLocalDB


I noticed I used a connection string to migrate an Identity Database. No matter what I did I looked and looked but I couldn't find the database. So I re-evaluated my connection strings and noticed they're not that similar:

var connectionString = @"Server=localhost;Database=MyDatabase;Trusted_Connection=True;"
var connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=gritzy.IdentityServer4.dbo;trusted_connection=yes;";

One just specified the server as localhost, and the other doesn't even specify a server at all.

I was under the impression that localhost would just use the default MSSQLSERVER Instance name.

What is the difference between the Data Source, and server?


Solution

  • "Data Source" and "Server" are synonyms, so no difference.

    localhost specifies the default SQL Server instance on your machine.

    (LocalDb)\MSSQLLocalDB is the default LocalDB instance on your machine