1

I am trying to connect to my SQL Server Express using migration. The migration is successful but while updating I am getting 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. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

appsetings.json

{
"Logging": {
"LogLevel": {
  "Default": "Information",
  "Microsoft": "Warning",
  "Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DemoLoginContextConnection": "Server=(DESKTOP-48LBLF\\SQLEXPRESS)\\mssqllocaldb;Database=DemoLogin;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

SSMS

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Moeez
  • 494
  • 9
  • 55
  • 147
  • That's an invalid `server` value – Panagiotis Kanavos Nov 10 '20 at 09:03
  • @PanagiotisKanavos I have tried to add a valid one but still it's not working – Moeez Nov 10 '20 at 09:30
  • Have you checked services.msc and verified that the SQL Server instance is actually running? – Tieson T. Nov 10 '20 at 09:46
  • @TiesonT. yes the sql server is running – Moeez Nov 10 '20 at 09:51
  • @Moeez what *did* you try? The error you got when you tried this invalid connection string doesn't count. There are a *lot* of duplicate questions for this specific error and the reason is always a wrong server name or an inaccessible server, either because it's not running or because it's blocked by a firewall – Panagiotis Kanavos Nov 10 '20 at 10:04
  • Does this answer your question? [Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?](https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci) – Panagiotis Kanavos Nov 10 '20 at 10:04
  • @PanagiotisKanavos my SSMS is working perfectly alright. – Moeez Nov 10 '20 at 10:04
  • @Moeez which means your connection string is wrong. Or you're trying to connect to a remote server that doesn't allow remote connections. – Panagiotis Kanavos Nov 10 '20 at 10:05
  • @PanagiotisKanavos I have tried each and every possible solution but still unable to resolve my problem – Moeez Nov 10 '20 at 10:29
  • @Moeez tried *what exactly*? There are no tricks required to connect to SQL Server, no matter the edition. The very fact you can connect using another client tool, SSMS, means the problem is in your code and connection string. You *haven't* posted your code or a valid connection string yet. Or even code that actually reproduces the error. Just a JSON string – Panagiotis Kanavos Nov 10 '20 at 10:32
  • @Moeez are you sure you're using the correct settings file? Create a new, empty console application and add *only* the minimum code needed to connect using a hard-coded connection string. Just create a `SqlConnection` object with the hard-coded connection string and call `Open()`. Try that on the same machine where you used SSMS – Panagiotis Kanavos Nov 10 '20 at 10:38

1 Answers1

3

As your screenshot shows - the server/instance name should be just DESKTOP-48LBLF\\SQLEXPRESS - not what you have right now....

Try this:

"ConnectionStrings": {
    "DemoLoginContextConnection": "Server=DESKTOP-48LBLF\\SQLEXPRESS;Database=DemoLogin;Trusted_Connection=True;MultipleActiveResultSets=true"
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459