コード例 #1
0
        /// <summary>
        /// The execute reader.
        /// </summary>
        /// <param name="connection">
        /// The connection.
        /// </param>
        /// <param name="transaction">
        /// The transaction.
        /// </param>
        /// <param name="commandType">
        /// The command type.
        /// </param>
        /// <param name="commandText">
        /// The command text.
        /// </param>
        /// <param name="commandParameters">
        /// The command parameters.
        /// </param>
        /// <param name="connectionOwnership">
        /// The connection ownership.
        /// </param>
        /// <returns>
        /// The <see cref="OracleDataReader"/>.
        /// </returns>
        private static OracleDataReader ExecuteReader(
            OracleConnection connection,
            OracleTransaction transaction,
            CommandType commandType,
            string commandText,
            OracleParameter[] commandParameters,
            OracleConnectionOwnership connectionOwnership)
        {
            // create a command and prepare it for execution
            var cmd = new OracleCommand();

            PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters);

            // create a reader
            OracleDataReader dr;

            // call ExecuteReader with the appropriate CommandBehavior
            if (connectionOwnership == OracleConnectionOwnership.External)
            {
                dr = cmd.ExecuteReader();
            }
            else
            {
                dr = cmd.ExecuteReader((CommandBehavior)((int)CommandBehavior.CloseConnection));
            }

            return(dr);
        }
コード例 #2
0
		/// <summary>
		/// Create and prepare an OracleCommand, and call ExecuteReader with the appropriate CommandBehavior.
		/// </summary>
		/// <remarks>
		/// If we created and opened the connection, we want the connection to be closed when the DataReader is closed.
		/// 
		/// If the caller provided the connection, we want to leave it to them to manage.
		/// </remarks>
		/// <param name="connection">a valid OracleConnection, on which to execute this command</param>
		/// <param name="transaction">a valid OracleTransaction, or 'null'</param>
		/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
		/// <param name="commandText">the stored procedure name or PL/SQL command</param> 
		/// <param name="commandParameters">an array of OracleParameters to be associated with the command or 'null' if no parameters are required</param>
		/// <param name="connectionOwnership">indicates whether the connection parameter was provided by the caller, or created by OracleHelper</param>
		/// <returns>OracleDataReader containing the results of the command</returns>
		private static OracleDataReader ExecuteReader(OracleConnection connection, OracleTransaction transaction, CommandType commandType, string commandText, OracleParameter[] commandParameters, OracleConnectionOwnership connectionOwnership)
		{	
			//create a command and prepare it for execution
			OracleCommand cmd = new OracleCommand();
			PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters);
			
			//create a reader
			OracleDataReader dr;

			// call ExecuteReader with the appropriate CommandBehavior
			if (connectionOwnership == OracleConnectionOwnership.External)
			{
				dr = cmd.ExecuteReader();
			}
			else
			{
				dr = cmd.ExecuteReader((CommandBehavior)((int)CommandBehavior.CloseConnection));
			}

			return (OracleDataReader) dr;
		}
コード例 #3
0
ファイル: MsOracle.cs プロジェクト: JuRogn/OA
 /// <summary>
 /// 执行一个OracleCommand(返回一个结果OracleDataReader)
 /// </summary>   
 /// <param name="connection">有效的 OracleConnection</param>
 /// <param name="transaction">有效的 OracleTransaction, or 'null'</param>
 /// <param name="commandType">命令类型 (stored procedure, text, etc.)</param>
 /// <param name="commandText">存储过程名称或 PL/SQL</param> 
 /// <param name="commandParameters">以一个数组的形式返回OracleParameters </param>
 /// <param name="connectionOwnership">indicates whether the connection parameter was provided by the caller, or created by OracleProvider</param>
 /// <returns></returns>
 private static OracleDataReader ExecuteReader(OracleConnection connection, OracleTransaction transaction, CommandType commandType, string commandText, OracleParameter[] commandParameters, OracleConnectionOwnership connectionOwnership)
 {
     OracleCommand cmd = new OracleCommand();
     PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters);
     OracleDataReader dr = null;
     try
     {
         if (connectionOwnership == OracleConnectionOwnership.External)
         {
             dr = cmd.ExecuteReader();
         }
         else
         {
             //  dr = cmd.ExecuteReader((CommandBehavior)((int)CommandBehavior.CloseConnection));
             dr = cmd.ExecuteReader();
         }
         if (transaction != null)
         {
             transaction.Commit();
         }
         return (OracleDataReader)dr;
     }
     catch
     {
         if (transaction != null)
         {
             transaction.Rollback();
         }
         throw;
     }
 }
コード例 #4
0
ファイル: OracleHelper.cs プロジェクト: yesnoba/54bang
        /// <summary>
        /// Create and prepare a SqlCommand, and call ExecuteReader with the appropriate CommandBehavior.
        /// </summary>
        /// <remarks>
        /// If we created and opened the connection, we want the connection to be closed when the DataReader is closed.
        /// 
        /// If the caller provided the connection, we want to leave it to them to manage.
        /// </remarks>
        /// <param name="connection">A valid OracleConnection, on which to execute this command</param>
        /// <param name="transaction">A valid OracleTransaction , or 'null'</param>
        /// <param name="commandType">The CommandType (stored procedure, text, etc.)</param>
        /// <param name="commandText">The stored procedure name or T-SQL command</param>
        /// <param name="commandParameters">An array of OracleParameters to be associated with the command or 'null' if no parameters are required</param>
        /// <param name="connectionOwnership">Indicates whether the connection parameter was provided by the caller, or created by OracleHelper</param>
        /// <returns>OracleDataReader containing the results of the command</returns>
        private static OracleDataReader ExecuteReader(OracleConnection connection, OracleTransaction transaction, CommandType commandType, string commandText, OracleParameter[] commandParameters, OracleConnectionOwnership connectionOwnership)
        {
            if (connection == null) throw new ArgumentNullException("connection");

            bool mustCloseConnection = false;
            // Create a command and prepare it for execution
            OracleCommand cmd = new OracleCommand();
            try
            {
                PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection);

                // Create a reader
                OracleDataReader dataReader;

                // Call ExecuteReader with the appropriate CommandBehavior
                if (connectionOwnership == OracleConnectionOwnership.External)
                {
                    dataReader = cmd.ExecuteReader();
                }
                else
                {
                    dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                }

                // Detach the OracleParameters from the command object, so they can be used again.
                // HACK: There is a problem here, the output parameter values are fletched
                // when the reader is closed, so if the parameters are detached from the command
                // then the SqlReader can�t set its values.
                // When this happen, the parameters can�t be used again in other command.
                bool canClear = true;
                foreach (OracleParameter commandParameter in cmd.Parameters)
                {
                    if (commandParameter.Direction != ParameterDirection.Input)
                        canClear = false;
                }

                if (canClear)
                {
                    cmd.Parameters.Clear();
                }

                return dataReader;
            }
            catch
            {
                if (mustCloseConnection)
                    connection.Close();
                throw;
            }
        }
コード例 #5
0
        private static OracleDataReader ExecuteReader(OracleConnection connection, OracleTransaction transaction, CommandType commandType, string commandText, OracleParameter[] commandParameters, OracleConnectionOwnership connectionOwnership)
        {
            //create a command and prepare it for execution
            OracleCommand cmd = new OracleCommand();

            PrepareCommand(cmd, connection, transaction, commandType, commandText, commandParameters);

            //create a reader
            OracleDataReader dr;

            // call ExecuteReader with the appropriate CommandBehavior
            if (connectionOwnership == OracleConnectionOwnership.External)
            {
                dr = cmd.ExecuteReader();
            }
            else
            {
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            }

            // detach the OracleParameters from the command object, so they can be used again.
            cmd.Parameters.Clear();

            return(dr);
        }