Konrad Viltersten
Konrad Viltersten

Reputation: 39268

Can't connect to local SQL Server Express

I've switched from AzureDb to a local SQL Server Express instance for my project. I can connect to the instance using Management Studio and see that the server is the usual .\sqlserver with sa and a dummy password. The actual database isn't created yet but I can access the server and see system databases as well as create logins.

However, trying to perform a migration database update, I get the following 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. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 26 - Error Locating Server/Instance Specified)

Naturally, I suspected something with my connection string (which I still do).

"ConnectionStrings": { ...
   "SqlServer": "Server=.\\sqlserver;Database=Blopp;Uid=sa;Pwd=Abc123();"
}

I've tried all the usual variations - single backslash, quadrupple backslash, forwardslash, at-char in the beginning, (localhost) instead of dot, computer name instead of dot etc. I'm out of ideas what else it might be. I've tried creating the DB manually. I tried using caps (although I know it's case insensitive). Nothing helped...

Proof of the usual effort: here (SO), here (MSDN), here (SO), here (SO), here (Hanselman), here (client protocol/service running).

What on earth am I missing?

Upvotes: 0

Views: 1503

Answers (1)

Guilder
Guilder

Reputation: 484

Base on the error, you have either a Network or a SQL configuration problem.

To further confirm this, you can do a UDL test (or the most basic non SSMS test you can do), Ref: How to perform a UDL test to check the SQL Server Connectivity.

The first answer to Why am I getting “Cannot Connect to Server - A network-related or instance-specific error”? has a good troubleshooting checklist for the kind of error you mention.

If your UDL test works, but you still cannot connect. Check your connection string. An easy way to do so is: Go to Visual Studio (Visual Studio not SQL Server Management Studio) and do:

  1. Go to Tools -> Connect to Database.
  2. Under Server Name Select your Database Server Name (Let the list Populate if it's taking time).
  3. Under Connect to a Database, Select Select or enter a database name.
  4. Select your Database from Dropdown.
  5. After selecting Database try Test Connection.
  6. If Test Connection Succeeds, Click Ok.
  7. In Visual Studio go to View -> Server Explorer.
  8. In the "Server Explorer" window, Under Data Connections, Select your Database. Right Click your Database -> Click Properties.
  9. In Properties window you will see your Connection String.

Taken from: Juned Khan Momin answer to this question: How to get the connection string from a database

Upvotes: 1

Related Questions