Skip to content

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

@galkinvv

Description

@galkinvv

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions