SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: )

 

How to fix below error


(1)   SQL SERVER – FIX : ERROR : (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: )


or 


(2)   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) (.Net SqlClient Data Provider)


------------------------------

For help, click: https://docs.microsoft.com/sql/relational-databases/errors-events/mssqlserver--1-database-engine-error


------------------------------

Error Number: -1

Severity: 20

State: 0



------------------------------

Program Location:


   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)

   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)

   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)

   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)

   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)

   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)

   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)

   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)

   at System.Data.SqlClient.SqlConnection.Open()

   at Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService.ValidateConnection(UIConnectionInfo ci, IServerType server)

   at Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()




 


Before doing any troubleshooting, i would request you to follow below steps primarily



 Open Command Prompt and run below command (Winkey+R then type cmd in run window and hit enter)


netstat -an 



Check under Local Address:listening port (Highlighted fields are port, and SQL server by default uses TCP 1433 port)

Currently SQL server is installed on this server, also all SQL services are running and able to access this database server from local but while accessing same from remote server it is giving error which mentioned above. 

Post running netstat -an command i can check if server is listening 1433 port or not. In above case/as per screenshot there is no listening port on TCP 1433, If server is not listening this port locally then how client machine will connect with this port...


Once you install the SQL server you need to follow below steps so client can connect this SQL  server/instance






Open SQL Server Configuration Manager


Go to SQL Server Network Configuration

Select Protocols for MSSQLServer

Check TCP/IP is Disabled






Double click on TCP/IP

Go to Protocol tab, and under Enabled section select "Yes"



Go to IP Addresses tab


IPALL under TCP Port type 1433 port

and Click on Apply and then OK


To reflect those changes you need to restart SQL services.

Go to SQL Services and restart the SQL Services





Once services are  up then again open command prompt and run netstat -an command





You will see now 1433 TCP port there
























Now go to client machine and connect the SQL server ............................



If you enjoyed this article, follow and share it with your friends and colleagues!!!!!!!!!!! 👍


Posted By : Kamlesh Gaur

Comments