Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

First database connection takes much longer on some machines when using managed SNI #3138

Unanswered
Ririshi asked this question in Q&A
Discussion options

I'm using SqlClient 5.2.2 with EFCore 8.0.11 in multiple .NET 8.0 apps. I'm finding that using the AppContext switch to enable managed SNI causes a very noticeable slowdown in some cases. The first time the app makes a database connection, it takes a lot longer on some machines compared to others.

We use context.Database.CanConnect() to check if we can connect to the database before continuing the startup.
When running on my local development machine (Windows 10 laptop), this check absolutely takes less than a second.
However, when running on the production machine (Windows Server 2019 Datacenter VM), it takes around 15 seconds to make the first connection.

Afterwards, the apps run completely fine without any perceived slowness. In both cases, I'm connecting to the same database server (MS SQL Server 2019), hosted on a separate VM, using its IP address in the connection string. I'm using the same login details (username + password) for both connections.

My first feeling is that it has to wait for something to time out before moving on, but I haven't found out how to debug this. I'm hoping someone can help me figure out what is going on here, unless this simply falls under "it's not production ready, don't use it yet". Please let me know if you need other information to be able to help!

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Just a comment that's not really helping, but in case you did not know:
https://learn.microsoft.com/en-us/sql/connect/ado-net/appcontext-switches?view=sql-server-ver16#enabling-managed-networking-on-windows

This switch toggles the driver's behavior to use a managed networking implementation in .NET Core 2.1+ and .NET Standard 2.0+ projects on Windows, eliminating all dependencies on native libraries for the Microsoft.Data.SqlClient library. It is for testing and debugging purposes only.

You must be logged in to vote
1 reply
Comment options

Yeah, thanks, I did guess that might be the case in my OP. Regardless, I imagine the managed version should one day be production-ready, so it would be interesting to explore and fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /