public DbDataReader ExecuteReader(QueryCommand qry, out string connectionString) { AutomaticConnectionScope scope = new AutomaticConnectionScope(this); WriteToLog(() => string.Format("ExecuteReader(QueryCommand):\r\n{0}", qry.CommandSql)); // Added for supporting PetaPoco integration for optimized object hydration connectionString = scope.Connection.ConnectionString; DbCommand cmd = scope.Connection.CreateCommand(); cmd.Connection = scope.Connection; //CreateConnection(); if (scope.IsUsingSharedConnection && CurrentSharedTransaction != null) { cmd.Transaction = CurrentSharedTransaction; } cmd.CommandText = qry.CommandSql; cmd.CommandType = qry.CommandType; AddParams(cmd, qry); //this may look completely lame //but there is a bug in here... DbDataReader rdr; //Thanks jcoenen! try { // if it is a shared connection, we shouldn't be telling the reader to close it when it is done rdr = scope.IsUsingSharedConnection ? cmd.ExecuteReader() : cmd.ExecuteReader(CommandBehavior.CloseConnection); } catch (Exception) { // AutoConnectionScope will figure out what to do with the connection scope.Dispose(); //rethrow retaining stack trace. throw; } return(rdr); }
public DbDataReader ExecuteReader(QueryCommand qry) { AutomaticConnectionScope scope = new AutomaticConnectionScope(this); if (Log != null) { Log.WriteLine(qry.CommandSql); } #if DEBUG //Console.Error.WriteLine("ExecuteReader(QueryCommand):\r\n{0}", qry.CommandSql); #endif DbCommand cmd = scope.Connection.CreateCommand(); cmd.Connection = scope.Connection; //CreateConnection(); cmd.CommandText = qry.CommandSql; cmd.CommandType = qry.CommandType; AddParams(cmd, qry); //this may look completely lame //but there is a bug in here... DbDataReader rdr; //Thanks jcoenen! try { // if it is a shared connection, we shouldn't be telling the reader to close it when it is done rdr = scope.IsUsingSharedConnection ? cmd.ExecuteReader() : cmd.ExecuteReader(CommandBehavior.CloseConnection); } catch (Exception) { // AutoConnectionScope will figure out what to do with the connection scope.Dispose(); //rethrow retaining stack trace. throw; } return(rdr); }