Connecting to SQLExpress Database takes long time

Lorne Johnson 0 Reputation points
2025-05-09T18:00:30.5266667+00:00

Upgraded .net 4.8 C# app to .net 8. The new version takes 30 seconds to connect to SQLExpress database on server (\ServerName\SQLExpress). Original version took less than 1 second to connect to same server. Management Studio and reporting tool also take less than 1 second to connect. Built a small app in .net 6 and 8 and both take 30 seconds to connect. Once the first connection completes all of the subsequent connections are less than a second. Looking for advice as to where I can look to figure out where the delay is cominmg from. I believe I have ruled out network traffic and the server. Seems .net 6/8 first connection is taking a long time to resolve but once it does it is fine.

Here are the commands I am using:

        CPLdbconnect = ("Data Source = Server\\sqlexpress; " +

        "Initial Catalog = CPL; " +

        "Persist Security Info = True; " +

        "User ID = userid; " +

        "Password = password; " +

        "TrustServerCertificate = True; " +

        "Connect Timeout = 60; ");

.net 6 - using System.Data.SqlClient.SqlConnection con = new(CPLdbconnect);

.net 8 - using Microsoft.Data.SqlClient.SqlConnection con = new(CPLdbconnect);

con.Open();

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,242 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.