Slow SQL Connection using .NET5 vs .NET Framework 4.7

Engineer 21 Reputation points
2022-05-04T19:52:21.693+00:00

I've got two very basic c# applications. One targeting .NET Fremework 4.7.2, the other targeting .NET 5.0. They were created at the same time, they are very simple programs that just connect to an SQL database using a connection string, perform a simple query, then disconnect.

I'm amazed at the difference in connection time between the two versions. The .net fremework 4.7 version will connect in 2.5 seconds.

The .NET 5.0 verison takes over 22 seconds to connect. Once connected the data transfer is fast enough, but the initial connection is crazy.

We even tried .NET 6.0 but got the same results.

Has anyone seen anything like this?

Here's the connection string:

connstring= "Server=servername\instancename;User Id=username;Password=***;Encrypt=false;"

SqlConnection conn = new SqlConnection(connString)

We're using System.Data.SqlClient

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,676 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,223 questions
{count} votes

Accepted answer
  1. Karen Payne MVP 35,031 Reputation points
    2022-05-04T21:31:56.827+00:00

    First test local, going to do a remote next

    199021-figure1.png

    Remote test to one of our data centers, faster than the local connection

    199005-figure2.png


1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,031 Reputation points
    2022-05-04T20:30:07.837+00:00

    Doubtful it is the connection. I've never had an issue with connecting with .NET Core projects.

    Checkout the following project, I connect in less than one second.

    My guess is dAdapter.Fill(ds); connects fine but something else is going on other than the actual opening of the connection.