Skip to content

6.1.0: Taking a long time to connect #3523

Closed

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

  1. Wraith2 commented on Jul 28, 2025

    @Wraith2
    Contributor

    When I test against an azure server.

    Connection successful!
    Time taken to connect: 218 ms
    

    connecting to a local sql 2022 instance:

    Connection successful!
    Time taken to connect: 208 ms
    

    It might be worth checking your networking to see if there is some stall in name resolution. Try using the ip address and port directly instead of a name for example.

  2. pietroserrano commented on Jul 28, 2025

    @pietroserrano

    I have the same issue with SQL Server 2019 and .NET8.
    When running 6.0.2 on my system this took 1040ms, in 6.1.0ms this takes 4494 ms.

  3. chenhw commented on Jul 29, 2025

    @chenhw

    When I test against an azure server.

    Connection successful!
    Time taken to connect: 218 ms
    

    connecting to a local sql 2022 instance:

    Connection successful!
    Time taken to connect: 208 ms
    

    It might be worth checking your networking to see if there is some stall in name resolution. Try using the ip address and port directly instead of a name for example.

    No, it has nothing to do with this. I am using the server IP address in the LAN and it takes a long time to connect. It seems to be related to the version of SQL Server.

  4. ErikEJ commented on Jul 29, 2025

    @ErikEJ
    Contributor

    @chenhw Which server version?

  5. Wraith2 commented on Jul 29, 2025

    @Wraith2
    Contributor

    OP says 2019, since I tested on 2022 and am fine it must be a 2019 problem. I don't have 2019 installed, I'd have to build a vm to test it.

  6. chrishardstaff commented on Jul 29, 2025

    @chrishardstaff
    Author

    This was connecting with an IP address - I will set up a SQL2022 server to test.

  7. chrishardstaff commented on Jul 29, 2025

    @chrishardstaff
    Author

    I'm getting the same results using a SQL2022 server - this is a remote server, I don't seem to have an issue when connecting to a local database server.

  8. ErikEJ commented on Jul 29, 2025

    @ErikEJ
    Contributor

    @chrishardstaff Do you connect via IP address or DNS name?

  9. chrishardstaff commented on Jul 29, 2025

    @chrishardstaff
    Author

    @ErikEJ IP address

  10. Wraith2 commented on Jul 29, 2025

    @Wraith2
    Contributor

    A thought. Is your client running on windows or linux? It changes what networking implementation the library uses. I tested on windows which has a native sni component but non-windows use the managed implmentation which can be forced on windows with an appcontext switch.

  11. chrishardstaff commented on Jul 29, 2025

    @chrishardstaff
    Author

    I'm using windows

  12. ErikEJ commented on Jul 29, 2025

    @ErikEJ
    Contributor

    @chrishardstaff Could you share a (redacted) connection string?

  13. 40 remaining items

  14. cxjke commented on Dec 4, 2025

    @cxjke

    The issue is definitely real. We were forced to upgrade to 6.1.3 due to the .NET 10 EF Core libraries requiring >= 6.1.1. When connecting to an SQL Server 2019 or 2022 we experience the issue in our products.
    Regarding your question @cheenamalhotra : Didn't #3804 basically confirm at least the 2016 part?

  15. apoorvdeshmukh commented on Jan 13, 2026

    @apoorvdeshmukh
    Contributor

    Hi, we finally have a setup which consistently reproduces this issue. We are actively working on the fix and will post updates once this is fixed. Thank you for the patience.

  16. moved this from Investigating to In progress in SqlClient Boardon Feb 3, 2026
  17. apoorvdeshmukh commented on Feb 3, 2026

    @apoorvdeshmukh
    Contributor

    Can someone validate if the linked PR fixes the issue seen here?

  18. moved this from In progress to In review in SqlClient Boardon Feb 3, 2026
  19. moved this from In review to In progress in SqlClient Boardon Feb 3, 2026
  20. moved this from In progress to Done in SqlClient Boardon Feb 5, 2026
  21. added this to the 7.0.0-preview4 milestone on Feb 11, 2026
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