SQL Server Error 26 and SQL Server Error 40 appear when you try to connect to SQL Server. We will troubleshoot and try to fix them in the same article as both are related to connection issue. We recommend to use the below solutions for the both errors and to try to localize the problem.
The error Messages:
(provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)”
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)
“ Named Pipes Provider Error: 40 – Could not open a connection to SQL Server“.
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)
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 the SQL Server is configured to allow remote connections. (provided: Named Pipes Provider, error: 40- Could not open a connection to the SQL Server) (Microsoft SQL Server, Error: 2).
SQL Server Error 26 and SQL Server Error 40
What is SQL Server Error 26?
You will get this error message while trying to connect to a SQL Server named instance and not when you use default instance. The client stack could not receive SSRP response UDP packet from SQL Browser.
How to fix Error 26 on SQL Server?
- Recheck the server name for any error and fix it
- Check the instance name for any error
- Check if SQL Server browser is running
- Control if this instance exist on server
- Ping the server and check if DNS can be resolved correctly
What is SQL Server Error 40?
This error appears mostly when SQL Server does not allow remote connections, Firewall Settings or TCP/IP is not enabled. We will explain below all those in order to troubleshoot easy.
Read also other SQL Server Helping Posts:
How to fix error 40 on SQL Server?
- Check SQL Server is running
- Make sure that Allow Remote Connections is enabled on sql server properties
- Check if TCP/IP is enabled
- Configure to allow SQL Server in Firewall Settings
- Check for working fine SQL Server Browser
- Make sure that you can ping the SQL Server
Below we will explain the above steps in long way for better understanding and easy fix of SQL error 26 and sql error 40.
1. Check if SQL Services are running
Hint! If you are running SQL Server by using an instance name and you are not using a specific TCP/IP port number in your connection string, you must enable the SQL Server Browser service to allow for remote connections.
How to check if SQL Server Service is running?
- Go to SQL Server Configuration Manager > SQL Server Services
- Find the service SQL Server (MSSQLSERVER) if default or the name of your instance
- Check if is running – should be running state with a green indication
Using Windows Command Prompt
sc query mssqlserver
For named instance name use below by by replacing instancename with the actual SQL Server instance name.
sc query mssql$instancename
How to check if SQL Server Browser is running?
- Navigate to SQL Server Configuration Manager > SQL Server Services
- Find the SQL Server Browser Service
- Check if it is configured to start automatically and is started – should be with a green indication
Using Windows Command Prompt
sc query sqlbrowser
2. Try to Flush DNS
How to flush DNS?
- Click Start Button
- Type CMD and press enter
- Type this into the black window that appears: ipconfig /flushdns and press enter.
3. Make sure that allow Remote Connection is enabled
Check if remote connections is allowed for applications/client. This option need to be allowed to establish connections and perform operations on the server. Often this is the reason of SQL Server Error 26 and SQL Server Error 40.
How to check if the remote connection is enabled?
- Open ‘SQL Server Management Studio’
- Right click on database name and select ‘Properties’
- In ‘Properties’ window, select ‘Security’, enable `SQL Server and Windows Authentication mode` and click `OK`.
- Now restart the SQL server.
4. Check Firewall
Check the firewall status for any troubles:
- Open ‘Control Panel’ and after that ‘Windows Firewall’.
- Select ‘Change Settings’ In ‘Windows Firewall’,
- Add an exception for port ‘1434’ and name it ‘SQL Server’
- Enable by clicking on the checkbox
5. Connection String
This solution is on cases when you are using connection string and are you writing it wrongly. For example connection string used by .NET framework:
Server=serverAddress;Database=dbName;User Id=username;
Password=password;
- Check for each parameter passed in the connection string for any typographical errors.
- Control the validity of the username/password.
- Confirm if the given database exists.
6. TCP\IP Protocol
This solutions can work when you have mix of default and named instance or named instances only.
How to Enable TCP/IP port?
- Open SQL Server Configuration Manager
- Click on SQL Server Network Configuration and click on Protocols for Name
- Right-click on TCP/IP
- Click Enable
- Restart your SQL Server instance
If you want to use a static port for your instance (instead of dynamic that changes after every restart) you can change it here.
- Open Properties for TCP/IP protocol
- Go to IP Addresses tab
- Scroll down to IPAll section
- Remove 0 value from TCP Dynamic Ports
- Specify your port in TCP Port
You can use this port to connect to your instance by providing <servername>,<port> or <IP>,<port> as Server Name (yes, there is a comma, not a colon).
Conclusion:
We have explained some solutions to fix SQL Server Error 26 and SQL Server Error 40 and hope that you find the fix on those solutions. The both errors are included on the same article because they have almost the same troubleshoot. If you have any other solution worked for you comment below and we will try to include it on our article.