SQL Server connection string troubles

Viewed 76

I am working on an ASP.NET MVC project, which uses this connection string:

<add name="Name" 
     connectionString="Data Source=.;initial catalog=MyDBName;integrated security=True;multipleactiveresultsets=True;" />```

Note: the data source value is ., this works but after I reset my pc and reinstalled SQL Server, it no longer works, I get an 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.

until I change the . in the connection string to DESKTOP-1V12LN7\SQLEXPRESS.

My question is what does the value . in the connection string mean and why doesn't it work after reinstalling SQL Server?

1 Answers

The data source=. (or server=. or data source=(local), which are all equivalent) means : connect to the local machine and the default, unnamed instance of SQL Server - this is the default for all non-Express editions of SQL Server installed on your machine.

When you install SQL Server Express, by default, it doesn't get installed as the default, unnamed instance - but it uses a SQLEXPRESS instance name - so you need to change your connection string to:

  • .\SQLEXPRESS
  • (local)\SQLEXPRESS
  • DESKTOP-1V12LN7\SQLEXPRESS
Related