-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
I have an application in ASP.NET MVC + ASP.NET API (.NET 9, OS Windows Server 2022, MS SQL 2022), where I use the Dapper library (2.1.66) to call stored procedures (other queries are handled by EF 9.0.4).
Recently, I noticed that with a high volume of requests to call the same procedure but with different parameters, sometimes I receive data from the result of a different request's execution. It seems that both the SQL and C# code are correct. Additionally, I have been monitoring the database queries and intentionally added an OUTPUT parameter (FakeParameter) with a random GUID to make sure this is not a SQL code issue. Importantly, this error occurs occasionally for different input parameters, with no apparent pattern, except that both requests need to come almost simultaneously. In such cases, Request 1 will receive its correct data in response, but Request 2 will receive the same data as Request 1 instead of its own separate data.
Below are code examples:
List<SP_Result> data = null;
var args = new DynamicParameters(new
{
AccountId = model.AccountId,
SortField = model.OrderColumnNo,
SortDirection = model.OrderDirection,
});
args.Add("RecordsTotal", dbType: DbType.Int32, direction: ParameterDirection.Output);
args.Add("FakeParam", dbType: DbType.Guid, direction: ParameterDirection.Output);
using (var con = new SqlConnection(DBContext.Database.GetConnectionString()))
{
data = (await con.QueryAsync<SP_Result>("SPName",
args, commandType: CommandType.StoredProcedure)).ToList();
}
I am certain (through logging data to the logs) that the GUID value in FakeParam for Request 2 matches what was returned by the stored procedure call for the same request, but after calling ToList, the data returned is from Request 1.