JDBC failed connectivity to MSSQL server after TCP handshake - sql-server

Attempting to make a JDBC connection from client (Windows Server 2012) to server (MSSQL Server 2012 SP2 hosted on Windows Server) results in this error:
Connection Timeout Expired.  The timeout period elapsed while
attempting to consume the pre-login handshake acknowledgement.  This
could be because the pre-login handshake failed or the server was
unable to respond back in time.  The duration spent while attempting
to connect to this server was - [Pre-Login] initialization=273;
handshake=29736;  (Microsoft SQL Server, Error: -2)
Packet trace analysis:
After the TCP handshake, the client sends a TDS pre-login packet to the server, but with the bytes representing the version all set to 0.  The server doesn't respond (though the protocol indicates the server MUST respond in some way), so the client re-transmits and eventually the client sends a TCP reset to the server. 
Additional details:
Port 1433 is open on both the client and server.
No network or software is filtering traffic from client to server.
Connectivity to the server is successful from other machines on different domains using the same connection string.
Connectivity is successful from client to server at the data link layer (tested using Data Link Editor).
TCP/IP is enabled for IPv4 and IPv6 on both the client and server.
TLS is enabled on both servers.
We have tried 3 different JDBC drivers using Squirrel SQL & MSSQL Server Management Studio.  All provide the same error.  The drivers refer to the correct DLLs.
Tracert from client to server completes successfully.
We have tried modifying the connection string to force trust of the server certification, force encryption, increase connection timeout value to several minutes, etc.
.NET 4.5 is used on the client, but .NET 4.5 is also used on other machines that can successfully connect to the server.
What could be the issue? I'm out of ideas.

Related

The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement

I looked into bunch of similar questions but haven't find a solution for my problem. I have this error:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=501; handshake=29876; (.Net SqlClient Data Provider)
I try to connect remote SQL Server instance from my dev machine via SSMS, specify ip address, not domain name. Tried all combinations of connection options.
Things I already checked:
not a problem with DNS because I use IP address
me and server supports similar network protocol
server is running, SQL Browser is running, server name and credentials are correct
my dev machine supports all versions of security protocols (e.g. TLS 1.2) and ciphers
I checked option "trust server certificate"
tried set a big timeout like 5 mins and got a little different error:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) (.Net SqlClient Data Provider)
In my opinion such kinds of errors mean that something wrong with security stuff. All network problems and firewall restrictions should not be a reason.
I'm sure that the server configured correctly because other developers don't have such problem with the same server. And version of my SSMS is not older than others.

SQL server unable to login from specific servers

I am trying to setup a new MS SQL server, but i am having trouble connecting it to the main app servers.
Points to note and things i have tried:
People can connect to the server remotely from their machines without any issue.
Tried setting up and enabling all the ip configurations under the instance.
Able to connect to remote shared paths between these servers.
Able to see logs saying server is listening on 127.0.0.1 and ::1
Error seen:
Via IIS-
Connection Timeout Expired. The timeout period elapsed while
attempting to consume the pre-login handshake acknowledgement. This
could be because the pre-login handshake failed or the server was
unable to respond back in time. The duration spent while attempting
to connect to this server was - [Pre-Login] initialization=14800;
handshake=13501; ]
vis SQLCMD -
Unable to complete Login process due to delay in opening server
connection.
Is there somewhere else i should be looking.? I am not sure if the issue is with the App server or DB server even.

Connection from Azure Web App to On Premise SQL Server using Hybrid Connection is not working in a closed network environment

The installation on both Azure and Sql Server side is done exactly according to Microsoft specifications in
https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections.
The endpoint host is the SQL Server machine name using fixed port 1433.
The SQL Server is a named instance of SQL Server Express in a Windows 2012 Server.
The connection is also shown as Connected both on Azure and Server HCM sides.
I have done several similar installations before without any problems in more open networks, but in this case the
SQL Server is installed on a "security network" and the only TCP/IP connection opened from the server is to
the Service Bus relay on port 443. But this should be possible according to the specs.
When my Azure Web App tries to open the SQL connection it responds with the error:
"Connection Timeout Expired. The timeout period elapsed while attempting to consume
the pre-login handshake acknowledgement. This could be because the pre-login handshake
failed or the server was unable to respond back in time. The duration spent while attempting
to connect to this server was - [Pre-Login] initialization=0; handshake=15028; "
In Azure diagnostics tool tcpping also works fine to machinename:1433.
What could be the reason for this behaviour?
Are there still some more ports to open or some other settings to change?
EDIT: The solution which finally solved this problem was a quite obvious one. The original settings had the firewall for the on Premise server open only for the Service Bus relay on port 443, just as the specs said would be enough. By opening port 443 for all outbound TCP/IP addresses the connection started immediately to work from my Azure Web App. So there are obviously more addresses used by Hybrid Connection, but I haven't found which ones.

How to configure keepalive for MSSQL client which uses SQL Server Driver

I have a client application which uses SQL Server Driver to connect with a remote MSSQL Server. (Installed SQL Server 2012 in client and Server machines)
Once connection is established and if the connection is idle, i could see keepalive signals being sent by server, which is ACKed by client and sent from client, which is ACKed by server. (Using wireshark)
By default, a keepalive signal is sent every 30 seconds by server as well as client.
If i change the value of "Keep Alive" option in "SQL Server Network Configuration -> Protocols for MSSQLSERVER -> TCP/IP -> Properties" to "20000", server starts sending keepalive signals every 20 seconds.
Similar way, how do i configure the keepalive timeout value for client?
Where the default value is set?
I tried changing "Keep Alive" option in "SQL Native Client 11.0 Configuration -> Client Protocols -> TCP/IP -> Properties", but it didn't affect the client keepalive time.

Connection Timeout Expired ... [Pre-Login] initialization=211; handsake=14787;

I have to add "service based database" in my visual studio 2017 community, but i found this message:
"Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=211; handshake=14787;"
can anyone tell me what i must to do?
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.
this link might help you, Connection Timeout expired
I´ve had same issue. It was Network issue. Firewall was dropping the packets in application level. We have able to access Ip and port by telnet ok, but does not by any SQL Client. Please contact your network administrator

Resources