The connection's current state is connecting
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi, im using asp.net core 2.1 and this is my sample code:
`
[HttpGet] [Route("dashboarddounatdata")]
public IActionResult Dashboarddounatdata()
{
var connection = new SqlConnection(_connectionString);
var donutChart2 = new DonutChart2();
try
{
connection.Open();
var parameters = new DynamicParameters();
parameters.Add("AC1", dbType: DbType.Int32, direction: ParameterDirection.Output);
parameters.Add("AC2", dbType: DbType.Int32, direction: ParameterDirection.Output);
if (cnn.State == ConnectionState.Closed) cnn.Open();
var data = cnn.Query("stp_chart_dounat_SELECT", parameters, commandType: CommandType.StoredProcedure);
donutChart2.AC1 = parameters.Get<int>("AC1");
donutChart2.AC2 = parameters.Get<int>("AC2");
}
catch (Exception ex)
{
throw new Exception(String.Format("{0}.WithConnection()", GetType().FullName), ex);
}
finally
{
connection.Close();
}
return new OkObjectResult(donutChart2);
}`
But sometimes (random) i get this error:
System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is connecting.
at System.Data.SqlClient.SqlConnection.GetOpenTdsConnection(String method)
at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command)
at System.Data.SqlClient.SqlCommand.ValidateCommand(Boolean async, String method)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1053
at Dapper.SqlMapper.<QueryImpl>d__1361.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1081
at System.Collections.Generic.List1.AddEnumerable(IEnumerable1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 723
at LabratoryApi.Controllers.ReportController.Getdashboardweeklycounttestconfirm() in C:\Users\New folder\Back-End\LabratoryApi\Controllers\ReportController.cs:line 213
--- End of inner exception stack trace ---
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ReportController.cs line 213 and compare the local connection variable with the cnn instance used by Dapper. Then inspect Dapper's SqlMapper.cs around lines 723, 1053, and 1081 to determine whether the reported state originates in Dapper or the caller's connection handling. Done means a minimal reproducible case or a clearly identified application-side cause.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- api, backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100