Click here to Skip to main content
16,021,211 members
Please Sign up or sign in to vote.
2.71/5 (5 votes)
See more:
hi,

Can anyone know why this error comeing?

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)how to solve this error?
Posted
Updated 4-Oct-20 11:11am

The error is pretty explicit - and it even tells you what to do.
Check your connection string - in all probability it does not reference the SQL server instance correctly.
 
Share this answer
 
Comments
Harpreet_125 7-Oct-13 7:00am    
then how i am able to access data from the server??
check these things
1. Make sure your database engine is configured to accept remote connections(I you are using centralized database)
•Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
•Click on Surface Area Configuration for Services and Connections
•Select the instance that is having a problem > Database Engine > Remote Connections
•Enable local and remote connections
•Restart instance

2. Check the SQL Server service account
•If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding

3.If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application
•Usually the format needed to specify the database server is machinename\instancename
•Check your connection string as well
 
Share this answer
 
Comments
csharpbd 8-Nov-12 12:32pm    
Nice solution, thanks a lot. bcz today i face this types of prob...
thanks again!
uspatel 9-Nov-12 1:01am    
Thanks
Dev Concept 27-Oct-15 1:41am    
Thanks. Worked for me.
Please go Control Panel\All Control Panel Items\Administrative Tools\services and start SQL SERVER(SQLEXPRESS).it will work.
 
Share this answer
 
Comments
MMLTech 20-Sep-13 5:18am    
This solution worked for me. Thanks.
Member 9615112 31-Mar-14 9:32am    
thanks this worked for me.
Member 1656214 3-Jul-15 18:08pm    
I encountered a very similar issue with SQL Server 2012 R2. I used the same strategy and restarted SQL Server(MSSQLSERVER) through Administrative Tools\Service then was able to connect.
Member 12608240 4-Jul-16 12:32pm    
but i have not a option to restart SQL Server (MSQLSERVER)
Member 14623287 17-Oct-19 3:21am    
xsfs
You can check if your computer name and the user name is same or different. if same please change the user name or computer name. u can give it a try, coz i tried all blogs, forums, Google search and lots of things for almost 1 year to solve this problem. finally i did this and it solved my problem.
 
Share this answer
 
Comments
Sanchita Dutta 12-Mar-13 0:19am    
Thank you so much. It solved my problem.
Ashim Malgope 12-Mar-13 1:33am    
you welcome
Try adding a , and a port number as in ",1433" to the end of your connection string.

Its possible that WMI or some other service dependency required to resolve the database instance name wasnt working on you local machine.

Manually specifying the port will resolve this.
 
Share this answer
 
Try these Commands =>

C:>sqllocaldb stop MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" stopped.

C:>sqllocaldb delete MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" deleted.

C:>sqllocaldb create MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" created with version 13.0.1601.5.

C:>sqllocaldb start MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" started.
 
Share this answer
 
Above all are meaning full solutions but resolved this by Restarting the machine.Try this if not work any of the above solutions.
 
Share this answer
 
If you are using mac then this issue occurs due to a mistake in Connection String. Since docker is required so the connection is made by considering the server on the remote machine. Thus in Connection String, the Server is provided and it should be the IpAddress of the mac machine followed by the port number of the server.

"Server=MacMachineIpAddress,portnumberOfServer;Database=db_name;User Id=sa; Password=**yourPassword**;"

Hope this helps.
 
Share this answer
 

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