Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I create asp.net core mvc project with .net core 7.
now I want put my site on host. I do this and configure the Plesk but i get this error:
An unhandled exception occurred while processing the request.
Win32Exception: The system cannot find the file specified.
Unknown location

SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


What I have tried:

my connection string in appsetting.json is:
"data source=.\MSSQLSERVER2022;Initial Catalog  = myddb; User ID = myuser; Password = mypass;MultipleActiveResultSets = true;" 

how can fix this? please help.
Posted

Call your hosting provider and bring the error up with them. The error means your code cannot connect to the SQL Server because there's no server to be found. You might want to make sure the name is correct as you put ".\MSSQLSERVER2022". The "." portion of the name means the SQL Server is expected to be on the same machine as your web server code. That is rarely ever the case.
 
Share this answer
 
The error message is very clear. An instance of MS SQL Server named ".\MSSQLSERVER2022" does NOT exist on server machine or is NOT accessible from the WAN.

You can resolve your issue by doing the following:
1) check connection string, especially the name of MS SQL Server instance
See the examples of proper connections strings: SQL Server connection strings - ConnectionStrings.com[^]
2) If it's correct, configure MS SQL Server to be visible from outside
See: Lesson 2: Connecting from Another Computer - SQL Server | Microsoft Learn[^]
3) If you can NOT use your machine to act as an sql server, you'll need to find a service (provider).


BTW: if you store the connection string in your code, i'd strongly recommend to move it into configuration file. Please read this:
Connection Strings and Configuration Files - ADO.NET | Microsoft Learn[^]
Connection Strings - EF Core | Microsoft Learn[^]
 
Share this answer
 
v2
Comments
Member 11400059 7-Dec-23 3:25am    
currently I send the ticket to my host provider. also I save my connection string in appsetting file and all the project read connection from this file. thank your help. I going to read the link you provide as soon as posible.
Maciej Los 7-Dec-23 4:16am    
You're very welcome. :)
Richard Deeming 7-Dec-23 4:18am    
NB: Since the connection string is looking for an instance on the local machine, it doesn't need to be accessible from the WAN. :)
Andre Oosthuizen 7-Dec-23 13:55pm    
+5ed, great on the tutorials!
Maciej Los 8-Dec-23 3:03am    
Thank you, Andre :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900