2

I have a backgroundservice built in .Net Core that executes a SQL Server database procedure as follows:

public int ExecuteProcedure(string connectionString, string sql, Dictionary<string, object> parameters = null)
{
        var response = -99;
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            connection.Open();
            // Create a SqlCommand, and identify it as a stored procedure.
            using (SqlCommand sqlCommand = new SqlCommand(sql, connection))
            {
                sqlCommand.CommandType = CommandType.StoredProcedure;
                if(parameters != null)
                    SetParameters(sqlCommand, parameters);
                response = sqlCommand.ExecuteNonQuery();
            }
            connection.Close();
        }

        return response;
}

When I run the bakcgroundservice on my local machine it runs without problems but when I use docker and kubernetes I get the following error:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)

I have consulted in several places but all the answers I find are about restarting Visual Studio or IIS which does not apply in my case due to having the application in kubernetes

I would greatly appreciate your help.

1
  • Could you edit your question to include the full and complete Exception including stack trace as text? I suspect that it's dying in System.Net.Security.SslStream while trying to setup an SSL/TLS encrypted connection. Jul 18, 2020 at 10:30

1 Answer 1

5

The error is presented by the image used when building the docker container.

I was using the image: mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim but when I changed it to: mcr.microsoft.com/dotnet/core/runtime:3.1-bionic worked fine.

From what I have been consulting it seems that the image that was failing me has a version of the TLS that is not compatible to make the successful connection with SqlServer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.