Azure / Azure/elastic-db-tools

MSQ: Silent failure when attempting to Read MultiShardDataReader whose MultiShardConnection has been disposed

Open
#87 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
147
Forks
108
PR merge metrics
No merged PRs in 30d

Description

Scenario: Customer returned a MultiShardDataReader outside of its MultiShardConnection's using block and Read from it. The code seems to work, but the MultiShardDataRead returns false for the dataReader.Read() call. So the following code, would give a flawed result, without any warnings." This should either work or cause an error.

See related issue "Consider implementing support for CommandBehavior.CloseConnection". These 2 issues are 2 facets of the same underlying problem and need to be fixed together

Code:
MultiShardDataReader dataReader = null;

IEnumerable shards = shardMap.GetShards();

using (MultiShardConnection connection = new MultiShardConnection(shards, credentialsConnectionString))
{
using (MultiShardCommand command = connection.CreateCommand())
{
command.CommandType = commandType;
command.CommandText = commandText;
command.ExecutionOptions = executionOptions;
command.ExecutionPolicy = executionPolicy;

if (commandTimeout > 0)
{
command.CommandTimeout = commandTimeout;
}

if (parameters != null)
{
command.Parameters.AddRange(parameters);
}

dataReader = await command.ExecuteReaderAsync(cancellationToken);
}
}

return dataReader;

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.