SqlConnection ConnectRetryCount behaves differently between .NET Framework and .NET Core.
```c#
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);
}
}
```
Changed ConnectRetryCount value in .NET Core
ConnectRetryCount not work?
Have you tried Microsoft.Data.SqlClient?
I tried Microsoft.Data.SqlClient.
execution results of both versions were as follows.
almost same result ConnectRetryCount=1 and 5.
@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.
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
Hi @cheenamalhotra
I tried v1.1.0-build.19320.1-d0672d2. and this problem improved.
Thanks.