Error occurred during the per-login handshake

Youssef Al Amrousy 0 Reputation points
2023-05-28T15:24:20.2+00:00

I've installed docker and the sql server is now running on docker. Azure detects the server but doesn't connect. I've changed 'Trust server certificate' to true and still same problem. Tried also setting Encrypt to false but still nothing happens.

Here is the error:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - Undefined error: 0)

Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - Undefined error: 0)
   at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning(Boolean callerHasConnectionLock, Boolean asyncClose)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at Microsoft.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   at Microsoft.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(SqlConnectionEncryptOption encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean& marsCapable, Boolean& fedAuthRequired, Boolean tlsFirst, String serverCert)
   at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.<>c__DisplayClass48_0.
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,748 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Konstantinos Passadis 17,456 Reputation points MVP
    2023-05-28T16:33:22.9433333+00:00

    Hello @Youssef Al Amrousy !

    Welcome to Microsoft QnA!

    I understand you are getting error when trying to connect to your Docker SQL Server

    Have you been through this ---->

    https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver16&pivots=cs1-bash

    Just for reference have a look you might get something !

    Also

    There are some basic checks for you to go through , so please :

    1.     Check the network settings: Ensure that the SQL Server container is running with the correct network settings. By default, SQL Server listens on port 1433. Confirm that the container is exposing this port correctly and that there are no port conflicts with other services running on your host machine.

    2.     Verify the connection string: Double-check the connection string used by your application to connect to the SQL Server. Make sure it includes the correct server name or IP address, port number, and any required credentials. Ensure that the connection string matches the network configuration of your Docker container.

    3.     Test the connection within the container: Access the shell of the SQL Server container and try to connect to the SQL Server instance from within the container itself. This can help determine if the issue is related to the container or the interaction between the container and the host machine.

    4.     Check firewall settings: If you are running a firewall on your host machine, make sure that it allows incoming connections on the SQL Server port (default: 1433). You may need to create a rule to allow inbound connections to the SQL Server container.

    5.     Review logs: Check the logs of the SQL Server container to see if there are any specific error messages or warnings related to the connection issue. The logs can provide valuable insights into the problem.

    6.     Ensure the SQL Server instance is configured correctly: Verify that the SQL Server instance running in the Docker container is properly configured to accept remote connections and has the necessary network protocols enabled.

    7.     Restart the Docker service: In some cases, restarting the Docker service or restarting your host machine can help resolve networking-related issues.( I guess you tried this but i have to mention every possibility !)

    I hope this helps!

    Kindly mark the answer as Accepted and Upvote in case it helped!

    The answer or portions of it may have been assisted by AI Source: ChatGPT Subscription

    Regards

    0 comments No comments