Skip to content

Large Performance Difference between .NET 4.8 and .NET 10 when Connecting to Remote Database #3984

@danstur

Description

@danstur

Description

I see huge performance differences when using SqlConnection in .NET 10 compared to .NET 4.8 when connecting to certain remote database servers.

I expect there's some change in defaults that causes the issue, so a list of changes to try would be helpful. The database servers are not under our control, which makes analysis on that side rather difficult.

You can find very similar issues on the internet, e.g. on SO, but the often recommended solution of changing Server settings (https://serverfault.com/questions/179898/sql-server-timeout-on-first-attempt) is not helpful, since we cannot influence our clients server systems.
And since it works fine in .NET 4.8 it's hard to argue that the server has to be changed to accommodate issues with one specific client.

To reproduce

var sw = Stopwatch.StartNew();
using var conn = new SqlConnection("User ID=userName;Password=SomePassword;Data Source=192.168.5.15;Database=SomeDatabase;Encrypt=False");
await conn.OpenAsync(); // sync code behaves identical
sw.Stop();
Console.WriteLine($"Connection took {sw.ElapsedMilliseconds}ms.");

Running this under .NET 4.8 the connection takes about 200ms. With .NET 10 we're observing about 5000ms connection times.

Expected behavior

Similar performance characteristics between .NET 4.8 and .NET 10 when connecting to the database.

Further technical details

Microsoft.Data.SqlClient version: 6.1.4
.NET target: .NET 4.8 and .NET 10 (10.0.103)
SQL Server version: Windows Server 2019 Standard (10.0)
Operating system: Windows 11 24H2 on client side

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions