Commit 2a94c2b2 authored by Marc Gravell's avatar Marc Gravell

FIX: Issue 106 - cancel commands when disposing readers

parent 6bda9725
......@@ -810,8 +810,10 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
using (var cmd = SetupCommand(cnn, transaction, sql, info.ParamReader, param, commandTimeout, commandType))
{
using (var reader = cmd.ExecuteReader())
IDataReader reader = null;
try
{
reader = cmd.ExecuteReader();
var tuple = info.Deserializer;
int hash = GetColumnHash(reader);
if (tuple.Func == null || tuple.Hash != hash)
......@@ -826,7 +828,14 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
{
yield return (T)func(reader);
}
}
finally
{
if (reader != null)
{
if (!reader.IsClosed) cmd.Cancel();
reader.Dispose();
}
}
}
}
......@@ -2347,6 +2356,7 @@ public void Dispose()
{
if (reader != null)
{
if (!reader.IsClosed && command != null) command.Cancel();
reader.Dispose();
reader = null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment