-
Notifications
You must be signed in to change notification settings - Fork 539
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
Retrying queries or SQL commands fails with "The SqlParameter is already contained by another SqlParameterCollection" #81
Comments
Other users have reported this with the following stack traces:
|
The same issue was fixed for other APIs in 1072839. |
Is there a work-around for those like me that are using 6.1.3 with no option to install a beta version of 6.2.0? |
@glozanomoran There are no good workarounds. You would need to get the DbConnection and create and execute the command manually and wrap this in a |
Any idea when EF 6.2 will be released? For now I suspend the execution strategy for the Database.SqlQuery() and Database.ExecuteSqlCommand() but my initial plan was to actually add the retrying strategy for the operations behind these two methods. |
@glozanomoran We don't have a date for the release yet, but we are working on it. |
Thank you for your responses and patience. It's just that I saw in the roadmap that you planned to release EF 6.2 in Q2 2017: I just have to figure out whether to wait for the release of EF6.2 or to find a work-around. |
Just wanted to say that we have upgraded to Entity Framework 6.2 and I wanted to thank you for fixing this issue in this release. |
Hello Stepping through the code I can see deadlock error is thrown from the line:
Think the second catch block in ExecuteStoreQueryInternal also needs the same command.Parameters.Clear() and command.Dispose()?
Same for ExecuteStoreQueryInternalAsync. Thanks. |
What a coincidence because Friday we had the exact same error. We had an issue where a script with an error was run from SQL Server Management Studio and the started transaction was not committed nor rolled back and because of this one of the tables was locked and this was leading to the exact same error as described by takkip. |
Hi Arthur, Thanks. |
@takkip I removed it so we will look at it again, but thanks to @AndriySvyryd for also re-opening since that also tends to help. 😄 |
I am having the same exception but I can reproduce it in different way. This is not related to retrying strategy. var exp = _nwind.Database.SqlQuery<Order>("SELECT * FROM Orders WHERE Freight> @Freight AND OrderDate > @OrderDate ", parms).AsQueryable();
// below is the part of the another component. It gets the expression and does paging operations for the grid
var count = exp.Count();
var page = exp.Skip(10).Take(20);
var list = page.ToList(); and stacktrace is as follows: at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index, Object value) |
@faikozgur That looks like a different issue. You can test with my linked PR and see if it resolves for you, but manual queries plus additional IQueryable operations are a bit sketchy in ef6. I recommend you move to ef core for that, or perform your paging in your query yourself. |
I'm experiencing the same issue. This exception happened this morning:
Here's my
Here's my stack-trace. There's no
|
This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information. |
Hello All,
I came to know from issue tracker that EF guys fix issue on "The Sql query is attempt to be retried, but when a command is created and Sql parameter are
added, it fails as we are reusing the SQL parameters passed to the query." with changeset-1072839. Does this fix, will also fix the
same issue while retrying "DbCotext.Database.ExecuteSqlCommand" method having sql parameters.
I've check my application with EF 6.1.3 and
even today's nighly build of EF but when i'm using "DbCotext.Database.ExecuteSqlCommand" method having sql parameters passed as argument
while retrying will giving me "The SqlParameter is already contained by another SqlParameterCollection" exception.
Is this seperate issue in EF?
Thanks,
The text was updated successfully, but these errors were encountered: