示例#1
0
        public DbDataReader ExecuteReader(QueryCommand qry)
        {
            AutomaticConnectionScope scope = new AutomaticConnectionScope(this);

            WriteToLog(() => string.Format("ExecuteReader(QueryCommand):\r\n{0}", qry.CommandSql));

            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);
        }