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
Dapper looses parameters #1169
Comments
In the example project (correct me if I'm wrong), it's spinning up workers and never-ending threads on each is perpetuity until something breaks...what what breaks? Is it out of memory? Connections? Can you reproduce this with raw ADO.NET? I can't think of a reason this would fail in Dapper itself (if we hit resource exhaustion we should blow sky high), but something in lower I can see doing it. |
We have been having the same issue for one of our queries after starting to use IN @parameter with an IEnumerable. If we recycle our app pool the query starts to work again, making us believe it has something to do with the caching in Dapper. The problem is that we have only seen it in production and is sofar unable to reproduce it in dev. When we have seen the error, the app has been running for a while before trying to run the query, if we run it quite soon after the start it works as expected. Looking at the sql and parameters: |
@mattyas Thanks for the info here - that's extremely helpful to track this down. |
Completely agree with @mattyas, problem occurs only in arrays. I've found a workaround, if when calling method you'll add parameter buffered: false than the problem disappears, I wasn't able to reproduce it for 6 hours using my sample if using this workaround However disabling buffering is not a good solution, so it would be great if this bug will be actually fixed |
Unfortunately workaround mentioned in my previous post works for test project, but doesn't work for our actual program: using parameter buffered:false I receive the following exception:
Calling ToList inside using connection does not help to fix this problem. So it would be great if this bug will be fixed, it keeps causing troubles on our production system, occurring several times per day |
I have not been able to find a workaround for this problem. Moving from parameters of type IEnumerable to use xml made the problem less frequent (about one tenth as frequent) but it was not totally resolved. My last attempt to tackle this was to catch SqlException with Number 137 (parameter missing) and when that occurs call Dapper.SqlMapper.PurgeQueryCache and retry the command or query. After deploying this I have been able to verify that this works a intended;
With help from MiniProfiler.Integrations I can verify that when the query fails the parameters are not included in the database call but after purging the cache they are. |
Dapper version: 1.50.5 using (var conn = new SqlConnection(connString))
} |
we use workaround: try
{
result = await connection.QueryAsync(sql, map, parameterValues, null, splitOn: splitOn, commandTimeout: _commandTimeout).ConfigureAwait(false);
}
catch (SqlException e)
{
if (e.Message.Contains("Must declare the scalar variable"))
{
global::Dapper.SqlMapper.PurgeQueryCache();
await Task.Delay(10);
try
{
result = await connection.QueryAsync(sql, map, parameterValues, null, splitOn: splitOn, commandTimeout: _commandTimeout).ConfigureAwait(false);
}
}
else
{
throw;
}
} After clearing cache, the next error throws after about 2 days |
I have same issue. |
In some rare cases Dapper sends requests to SQLServer without parameters. I was able to reproduce it in test project:
https://github.com/dj-raphael/Dapper-test-lost-parameters
To reproduce, you should start this project in Visual Studio in Debug mode and wait for about a minute. However we encounter this problem from time to time (very rarely) in Release build on our production server. Here is the screenshot of exception we get:
https://github.com/dj-raphael/Dapper-test-lost-parameters/blob/master/exception.png
Here is the log obtained using MiniProfiler.Integrations library, I'm logging sql request before it was sent to SQLServer
https://github.com/dj-raphael/Dapper-test-lost-parameters/blob/master/example-log.txt
Log shows that I'm passing parameters to Dapper but SQLServer receives a request without any parameters at all. Another interesting fact is that it happens only when at least one of parameters is an array.
The text was updated successfully, but these errors were encountered: