Skip to content

6.1.0: Taking a long time to connect #3523

Description

@chrishardstaff

Describe the bug

When connecting to a remote server, version 6.1.0 is taking significantly longer than 6.0.2

using Microsoft.Data.SqlClient;

namespace SqlServerConnectTest
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var builder = new SqlConnectionStringBuilder();
            builder.DataSource = "xxx";
            builder.InitialCatalog = "xxx";
            builder.UserID = "xxx";
            builder. Password = "xxx";
            builder.TrustServerCertificate = true;
            builder.ApplicationName = "Connection test";
            builder.ConnectTimeout = 30;
            builder.Encrypt = true;

            Console.WriteLine(builder.ConnectionString);

            using (var cn = new SqlConnection(builder.ConnectionString))
            {
                try
                {
                    var stopwatch = System.Diagnostics.Stopwatch.StartNew();
                    cn.Open();
                    stopwatch.Stop();
                    Console.WriteLine("Connection successful!");
                    Console.WriteLine($"Time taken to connect: {stopwatch.ElapsedMilliseconds} ms");
                }
                catch (SqlException ex)
                {
                    Console.WriteLine($"SQL Error: {ex.Message}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"General Error: {ex.Message}");
                }
            }
        }
    }
}

When running 6.0.2 on my system this took 948ms, in 6.1.0ms this takes 16494 ms. This is running in .NET 9 and the SQL Server is 2019.

Expected behavior

The connection should happen in roughly the same time on both versions

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Regression 💥Issues that are regressions introduced from earlier PRs.Repro Available ✔️Issues that are reproducible with repro provided.

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions