Connection Timeout issue when trying to execute Non Async method using Dapper, Microsoft.Data.SqlClient V3.0.0 Stable in .NETFrameowork 4.8 WebApplication #1138
Closed
Description
Describe the bug
A clear and concise description of what the bug is.
Getting timeout issue while trying to execute Non Async method using Dapper and Microsoft.Data.SqlClient,.
Exception message:
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Stack trace:
System.InvalidOperationException at Dapper.SqlMapper.QueryMultipleImpl
### To reproduce
using (conn)
{
using (var multiple = conn.QueryMultiple("GetResult", commandType: System.Data.CommandType.StoredProcedure))
{
var result = multiple.Read().ToList();
}
}
Add below line in Application_Startup method in Global.asax:
AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.EnableRetryLogic", true);
Using Active Directory Integrated Authentication to connect Azure SQL DB.
### Expected behavior
It should return the result
### Further technical details
Microsoft.Data.SqlClient version: (found on the nuget V3.0.0 stable)
.NET target: (e.g. Framework 4.8)
ASP.NET MVC Application
SQL Server version: Azure SQL DB
Operating system: (e.g. Windows 10)
**Additional context**
Below is the Event Tracing in SqlClient:
<prov.DbConnectionHelper.ConnectionString_Get|API> 1
<sc.SqlConfigurableRetryLogicManager.ConnectionProvider|INFO> Requested the ConnectionProvider value.
<sc.AppConfigManager.FetchConfigurationSection|INFO> Successfully loaded the configurable retry logic settings from the configuration file's section 'SqlConfigurableRetryLogicConnection'.
<sc.AppConfigManager.FetchConfigurationSection|INFO>: Unable to load section `SqlConfigurableRetryLogicCommand`. ConfigurationManager failed to load due to configuration errors: System.Configuration.ConfigurationErrorsException: The value for the property 'maxTime' is not valid. The error is: The value must be inside the range 00:00:00-00:02:00.
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Web.HttpContext.GetSection(String sectionName)
at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)
at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Microsoft.Data.SqlClient.AppConfigManager.FetchConfigurationSection[T](String name) in H:\tsaagent1\_work\18\s\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\Reliability\AppConfigManager.cs:line 29
<sc.AppConfigManager.FetchConfigurationSection|INFO>: Unable to load custom `SqlConfigurableRetryLogicCommand`. Default value of `T` type returns.
<sc.SqlConfigurableRetryLogicLoader.CreateRetryLogicProvider|INFO> Entry point.
<sc.SqlConfigurableRetryLogicLoader.CreateRetryLogicProvider|INFO> Successfully created a SqlRetryLogicOption object to use on creating a retry logic provider from the section 'SqlConfigurableRetryLogicConnection'.
<sc.SqlConfigurableRetryLogicLoader.ResolveRetryLogicProvider|INFO> Entry point.
<sc.SqlConfigurableRetryLogicLoader.LoadType|INFO> The 'null' type is resolved.
<sc.SqlConfigurableRetryLogicLoader.CreateInstance|INFO> Entry point.
<sc.SqlConfigurableRetryLogicLoader.CreateInstance|INFO> The given type `SqlConfigurableRetryFactory` infers as internal `Microsoft.Data.SqlClient.SqlConfigurableRetryFactory` type.
<sc.SqlConfigurableRetryLogicLoader.CreateInstance|INFO> The `Microsoft.Data.SqlClient.SqlConfigurableRetryFactory.CreateFixedRetryProvider()` method has been discovered as the `CreateFixedRetryProvider` method name.
<sc.SqlConfigurableRetryLogicLoader.PrepareParamValues|INFO> Parameters are prepared to invoke the `Microsoft.Data.SqlClient.SqlConfigurableRetryFactory.CreateFixedRetryProvider()` method.
<sc.SqlConfigurableRetryLogicLoader.CreateInstance|INFO> Parameters are prepared to invoke the `Microsoft.Data.SqlClient.SqlConfigurableRetryFactory.CreateFixedRetryProvider()` method.
<sc.SqlConfigurableRetryLogicLoader.ResolveRetryLogicProvider|INFO> The created instace is a Microsoft.Data.SqlClient.SqlRetryLogicBaseProvider type.
<sc.SqlConfigurableRetryLogicLoader.CreateRetryLogicProvider|INFO> Successfully created a SqlRetryLogicBaseProvider object from the section 'SqlConfigurableRetryLogicConnection'.
<sc|SqlAuthenticationProviderManager|Ctor|Info>Neither SqlClientAuthenticationProviders nor SqlAuthenticationProviders configuration section found.
<sc.TdsParser.Connect|SEC> Active Directory Default authentication
<sc.TdsParser.Connect|SEC> Sending prelogin handshake
<sc.TdsParser.SendPreLoginHandshake|INFO> ClientConnectionID XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX, ActivityID XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX:2
<sc.TdsParser.Connect|SEC> Consuming prelogin handshake
<sc.TdsParser.Connect|SEC> Prelogin handshake successful
<sc.TdsParser.TdsLogin|SEC> Sending federated authentication feature request
<sc.TdsParser.TryRun|SEC> Received federated authentication info token
<sc.TdsParser.TryProcessFedAuthInfo> Processed FEDAUTHINFO token stream: STSURL: https://login.windows.net/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX, SPN: https://database.windows.net/
<sc.SqlInternalConnectionTds.OnFedAuthInfo> 4, Generating federated authentication token
Thanks..