In this article, I will explain How to trace and solve the below error
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgment.
This could be because the pre-login handshake failed or the server was unable to respond back in time.
Scenario
I have an ASP.Net website that connects to SQL server always-on failover cluster instance.
When I configured the Connection String inside Web.Config as SQL Authentication, the connection has been connected successfully.
Server=load balancer IP;Database=Database Name;User Id=User; Password=Password;
But when I tried to configure the Connection String as Windows Authentication.
Server=load balancer IP;Database=Database Name;Integrated Security =true;
I got the below error.
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgment.
This could be because the pre-login handshake failed or the server was unable to respond back in time.
By the way,
- The application pool service account has elevated privilege with SQL Server as
- Public server role and the user is mapping the correct database.
But unfortunately, the issue still persists!
Cause:
The “Connection Timeout expired” error commonly occurs in the following cases:
- An instance of the SQL Server Database Engine is not running.
- The SQL Server Browser service is not running.
- The TCP/IP is disabled.
- The server name was typed incorrectly.
- There are network problems.
- The TCP/IP port for the Database Engine instance is blocked by a firewall.
- The client and server are not configured to use the same network protocol.
Solution:
In this section, I will explain the above causes one by one in more details.
An instance of the SQL Server Database Engine is not running.
On each node, you should ensure that each SQL Server Database Engine is started and running properly by doing the following:
- Open SQL Server Configuration Manager.
- Make Sure that the SQL Server Services state is running.
- In case, it is not running try to start it.
- In case. it’s not started check SQL Server Service was unable to start.
The SQL Server Browser service is not running.
- Again, Open SQL Server Configuration Manager.
- Make sure that The SQL Server Browser service is running.
The TCP/IP is disabled.
- Again, Open SQL Server Configuration Manager.
- From right side, Navigate to SQL Server Configuration Network.
- Make sure that TCP/IP is enabled.
The server name was typed incorrectly
In my case, the problem was in the server name where I have used the Load Balancer IP that should be the SQL Alias name when using Windows Authentication. so that the connection string should be like this
Server=SQL Alias Name;Database=Database Name;Integrated Security =true
To get the SQL Alias name:
- Run Command Prompt as Administrator.
- Run the following Command.
CLICONFG.EXE
- The following Dialog should be shown > Click on Alias tab > Get the Server Alias.
In the end, you should make sure that you have provided the correct SQL Server name to avoid this issue.
There are network problems
- At the Application server, try to open the CMD as Administrator.
- Run “Ping” command with the Database Server IP for each node and for load balancer IP to ensure that the application server can reach to the database server and vice versa.
- Try to repeat the same “Ping” command from the Database server to the application server IP.
Use UDL file, to test the SQL Server instance access
Not mean you can reach the database server, you have access to the SQL server instance! So:
- Try to login with The application pool account that runs the website on the IIS to the application server.
- Then try to create a UDL file as mentioned at How to check SQL server instance connectivity from the application server to database server for a specific user without using SQL server management studio.
The TCP/IP port for the Database Engine instance is blocked by a firewall
The default port for TCP/IP is 1433 so you should make sure that The Database Engine is listening on port 1433 and it has not been changed,
To get the TCP port number via SQL Configuration Wizard.
- Open SQL Server Configuration Wizard.
- Navigate to SQL Server Network Configuration.
- Right click on TCP/IP > Properties > IP Address.
- Scroll down to IPALL > Check TCP Port.
To get the TCP Port number via T-SQL.
- Open SQL Server Management Studio.
- Use Master Database > Click on New Query.
- Run the following Query.
SELECT DISTINCT local_tcp_portFROM sys.dm_exec_connections WHERE local_tcp_port IS NOT NULL
- The output should be retrieved as shown below.
- Try to telnet the SQL Server IP to its TCP port.
Note: if the telnet command is not recognized, you should install telnet feature as mentioned at ‘telnet’ is not recognized as an internal or external command, operable program or batch file.
- If the port is not blocked, you should get the following.
- Else that the port is blocked and you will need to open it.
To open port on SQL Server.
- From SQL Server > Open Windows Firewall.
- From right side > Select Inbound Rules.
- Right click on Inbound Rules > Select New Inbound Rule.
- In Rule Type Step > Check Port.
- On Protocol and Port Step > Select TCP, Special Local Ports > Type the SQL Port.
The client and server are not configured to use the same network protocol.
- Open Network and sharing center on SQL Server.
- Change Adapter Settings.
- Right Click on Ethernet > Properties.
- If IPv6 has been checked, so It should be checked on the application server.
- If IPv6 has not been checked, so It should be unchecked on the application server.
Conclusion
In this article, I have tried to solve the below issue
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgment.
This could be because the pre-login handshake failed or the server was unable to respond back in time.
Thank you.. in my case the port number was different in both the node.
LikeLike
It’s great that you are getting ideas from this piece of writing as well as from our argument made here.
LikeLike
Asking questions are genuinely pleasant thing if you are not understanding anything completely, but this piece of writing offers nice understanding even.
LikeLike
Thanks for information …. save my work .. rsss
LikeLike
you are welcome 🙂
LikeLike
Hi Mohammed,
When I tried to connect the DB from SSMS from my application server I am getting the same error as mentioned in the post, but if I try it for the 2nd time I am able to login successfully without any problem.
SQL is installed in different server and I am trying to connect it from different server using SSMS.
any help will be really appreciated.
Regards
Anand
LikeLike
Really wonderful visual appeal on this internet site, I’d rate it 10.
LikeLike
Thanks!
LikeLike
Thank you for helping out, good info.
LikeLike
You’re welcome 🙂
LikeLike
Thanks designed for sharing such a nice opinion, article is pleasant, thats why i have read it entirely
LikeLike
Welcome 🙂 thanks for your feedback!
LikeLike
Hi there, of course this article is truly good and I have learned lot of things from it on the topic of blogging. thanks.
LikeLike
Glad to hear it helped you 🙂
LikeLike
Hi I am so glad I found your site, I really found you by error, while I was looking on Bing for something else, Regardless I am here now and would just like to say many thanks for a remarkable post and a all round interesting blog (I also love the theme/design), I don’t have time to browse it all at the minute but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the excellent work.
LikeLiked by 1 person
Thank you so much for your kind feedback ♥
LikeLike
you are really a good webmaster. The web site loading velocity is amazing. It sort of feels that you are doing any distinctive trick. Furthermore, The contents are masterwork. you have performed a excellent activity on this subject!
LikeLike