Skip to content
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

Misleading ADP_OpenReaderExists exception message on MARS-disabled Sql Connection when incorrectly doing parallel requests #82

Closed
galkinvv opened this issue Mar 27, 2016 · 7 comments
Assignees

Comments

@galkinvv
Copy link

I've discovered the issue using ordinary .net4.5 on Windows but further investigating shows that it is related to code that now is in the .net Core

While simultaneousely (incrorrcetly) using single SqlConnection with Multiple Active Result Sets (MARS) disabled an exception with text

<data name="ADP_OpenReaderExists" xml:space="preserve">
<value>There is already an open DataReader associated with this Command which must be closed first.</value>
</data>

Note that text mentions same "Command" but in reality the resource taht is wrongly shared is not command but connection.

The exception is raised from https://github.com/dotnet/corefx/blob/cf19c22be88b5ea31b5e2ea69ab3632f930b1e26/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlInternalConnectionTds.cs#L587

The comment

// if MARS is on, then a datareader associated with the command exists
// or if MARS is off, then a datareader exists

above raising the exception is absolutely correct - if MARS is on the exception text is correct - problem is in using multiple readers with single command. But if mars is off the checks above checking for any active datareaders for the same connection, not only for datareaders for the same command.

So the problem is that information about what scope (Connection or Command) was checked is not passed to exception cinstructor and it incorrectly always says that there is another reader associated with the command

@galkinvv
Copy link
Author

I think that problem raises quite commonly: see comments below this post: (not the post itself!) https://blogs.msdn.microsoft.com/spike/2009/08/20/there-is-already-an-open-datareader-associated-with-this-command-which-must-be-closed-first-explained/

@joshfree
Copy link
Member

@saurabh500 @corivera

@saurabh500 saurabh500 removed their assignment Apr 24, 2017
@divega divega transferred this issue from dotnet/corefx May 16, 2019
@divega
Copy link

divega commented May 16, 2019

As recently announced in the .NET Blog, focus on new SqlClient features an improvements is moving to the new Microsoft.Data.SqlClient package. For this reason, we are moving this issue to the new repo at https://github.com/dotnet/SqlClient. We will still use https://github.com/dotnet/corefx to track issues on other providers like System.Data.Odbc and System.Data.OleDB, and general ADO.NET and .NET data access issues.

@David-Engel
Copy link
Contributor

This sounds like a relatively simple fix. In https://github.com/dotnet/corefx/blob/cf19c22be88b5ea31b5e2ea69ab3632f930b1e26/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlInternalConnectionTds.cs#L587, we can throw an exception with a different message if mars is on versus off.

@yukiwongky
Copy link
Contributor

@galkinvv Attached is the driver with the fix in PR #250. Can you verify it works?
Microsoft.Data.SqlClient.1.1.0-dev.zip

@galkinvv
Copy link
Author

Thanks for the fix! However unfortunately now I doesn't have corresponding environment, so I can't actually test it.
Though, I reviewed the PR code:fix looks fine and the tests are looking similar to my older code that was causing this issue.

So I think that this bug should be closed after merging PR.

@yukiwongky
Copy link
Contributor

Closing this issue since PR #250 is merged.

@David-Engel David-Engel modified the milestones: 1.1.0, 1.1.0-preview2 Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants