Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Core SqlConnection ConnectRetryCount not work? #261

Closed
OdaShinsuke opened this issue Oct 12, 2019 · 5 comments
Closed

.NET Core SqlConnection ConnectRetryCount not work? #261

OdaShinsuke opened this issue Oct 12, 2019 · 5 comments
Milestone

Comments

@OdaShinsuke
Copy link

.NET Core SqlConnection ConnectRetryCount not work?

SqlConnection ConnectRetryCount behaves differently between .NET Framework and .NET Core.

To reproduce

static string connstr = @"Data Source=localhost;Initial Catalog=master;Integrated Security=True;Connect Timeout=5;Encrypt=False;";

static void Main(string[] args)
{
    Test_ConnectRetry();
    Console.ReadKey();
}
static void Test_ConnectRetry()
{
    Stopwatch s = null;
    try
    {
        using (var conn = new SqlConnection(connstr + "ConnectRetryCount=5;ConnectRetryInterval=5;"))
        using (var cmd = new SqlCommand(@"select 1", conn))
        {
            conn.Open();

            Console.WriteLine(cmd.ExecuteScalar());
            Console.WriteLine("net stop <sql server service>");
            Console.ReadKey(); // manually SQL Server service stop
            Console.WriteLine("SQL Server Service stoped!");
            s = Stopwatch.StartNew();

            cmd.ExecuteScalar();

            Console.WriteLine("not run");
        }
    }
    catch (Exception ex)
    {
        s.Stop();
        Console.WriteLine(ex.Message);
        // .NET Framwork is over 30000ms, .NET Core is about 7000ms
        Console.WriteLine(s.ElapsedMilliseconds);
    }
}
  • ElapsedMilliseconds
    • .NET Framework 4.7.2 + SqlClient 4.7.0
      • over 30000 milliseconds
    • .NET Core 3.0 + SqlClient 4.7.0
      • about 7000 milliseconds

Expected behavior

Changed ConnectRetryCount value in .NET Core

  • ConnectRetryCount=0
    • thrown exception immediately
  • ConnectRetryCount=1
    • thrown exception after about 7000 milliseconds
  • ConnectRetryCount=5
    • thrown exception after about 7000 milliseconds

ConnectRetryCount not work?

@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 12, 2019

Have you tried Microsoft.Data.SqlClient?

@OdaShinsuke
Copy link
Author

I tried Microsoft.Data.SqlClient.

  • 1.1.0-preview1.19275.1
  • 1.0.19269.1

execution results of both versions were as follows.

  • ConnectRetryCount=0
    • thrown exception immediately
  • ConnectRetryCount=1
    • thrown exception after about 14000 milliseconds
  • ConnectRetryCount=5
    • thrown exception after about 14000 milliseconds

almost same result ConnectRetryCount=1 and 5.

@cheenamalhotra
Copy link
Member

@OdaShinsuke

Thanks for reporting the issue. The behavior should be same as far as I can tell from implementation goals. We'll update you when we investigate the root cause.

@yukiwongky yukiwongky added this to the 1.2.0 milestone Oct 22, 2019
@cheenamalhotra
Copy link
Member

Hi @OdaShinsuke

We recently fixed a bug in Connection Resiliency (#304) that was broken in one of the 4.7.0-preview versions of System.Data.SqlClient and eventually landed in Microsoft.Data.SqlClient.

PR #310 contains the fix for this issue that has been merged, would you like to give it try to check if this is the same problem?

A NuGet package containing this fix can be found here: v1.1.0-build.19320.1-d0672d2

@OdaShinsuke
Copy link
Author

Hi @cheenamalhotra

I tried v1.1.0-build.19320.1-d0672d2. and this problem improved.
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants