Bobcares

MSSQL error 40 – How to fix it

by | Oct 1, 2019

Database errors can be frustrating. Especially when even the login to the SQL Server fails.

Usually, the MSSQL error 40 occurs when a user can’t connect to the SQL server.

At Bobcares, we often receive requests to fix MSSQL error 40 as part of our Server Management Services.

Today, let’s analyze the error and see how our Support Engineers fix it for our customers.

 

Causes for the error MSSQL Error 40

Now, let’s get into the details of the “Error: 40 – Could not open a connection to SQL Server“.

This error primarily happens when there are problems establishing database connection. The common causes for the error are MSSQL service failure or the closed MSSQL port.

 

How we fix MSSQL error 40

We just saw on what causes the MSSQL error 40.

We’ll now take a look at different error scenarios and how we fix the MSSQL error.

 

1. SQL service down

Recently, we had a customer who was facing a problem to get into the database. We helped him to fix the error by verifying the following details.

The most common reason that can cause the error was SQL service failure.

Therefore, we first verified whether the service was running. We verified the service from

Click Start >> Search services.

Here the server was in a stopped state. So we did a restart of the service. Also, we made sure that the SQL Server Agent was running.

In a similar way, the SQL service can also be verified from the command prompt. To do this, our Support Engineers use the command.

sc query mssqlserver
sc query sqlserveragent

 

2. Enable TCP/IP

Another common reason for the error can be disabling of TCP/IP protocol on the server.

Here, our Dedicated Engineers verify the details and enable TCP/IP.

We enable TCP/IP from the SQL server configuration manager.

Open SQL server configuration manager >> Expand SQL server network configuration >> Right click on TCP/IP >> Enable.

We will also verify the port mentioned in TCP/IP. By default, MSSQL runs on port 1433. We always make sure that the server listens correctly on the port.

 

3. Port not open in the firewall

In most cases, when the SQL service is running and the server has TCP/IP enabled, there should not be any errors.

However, if still the error happens our Support Engineers analyze the firewall setting in the server. The SQL port 1433 must be open on the server. If the port is not open, we open it in the Windows firewall.

Start >> Administrative Tools >> Windows Firewall with Advanced Security

Click on outbound rules >> Select new rule.

Now our engineers will add the rule to open MSSQL port.

That fixes the MSSQL error 40.

[Need assistance to fix MSSQL errors? We’ll help you.]

 

Conclusion

In short, MSSQL error 40 happens due to a lack of connection to the server. Today, we discussed how our Support Engineers fix the error by verifying the service and enabling the port 1433 in the server.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.