Exemplo n.º 1
0
        public DataSet ExecuteDbDataSet(DbCommand scdCommand)
        {
            DbConnection Conn = Conexao.abrirConexao();

            scdCommand.Connection = Conn;

            DbDataAdapter daAdapter = Conexao.obterDataAdapter(scdCommand.Connection);

            try
            {
                DataSet dsDados = new DataSet();
                daAdapter.SelectCommand = scdCommand;
                daAdapter.Fill(dsDados);

                daAdapter = null;
                return(dsDados);
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
            finally
            {
                daAdapter.Dispose();
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 2
0
 protected virtual void ConfigureParameter(DbParameter param,
                                           string name,
                                           DbType dbType,
                                           int size,
                                           ParameterDirection direction,
                                           bool nullable,
                                           byte precision,
                                           byte scale,
                                           string sourceColumn,
                                           DataRowVersion sourceVersion,
                                           object value)
 {
     try
     {
         param.DbType        = dbType;
         param.Size          = size;
         param.Value         = value ?? DBNull.Value;
         param.Direction     = direction;
         param.IsNullable    = nullable;
         param.SourceColumn  = sourceColumn;
         param.SourceVersion = sourceVersion;
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 3
0
        public DataTable ExecuteDbDataTable(DbCommand scdCommand, DbConnection Conn)
        {
            scdCommand.Connection = Conn;

            DbDataAdapter daAdapter = Conexao.obterDataAdapter(scdCommand.Connection);

            try
            {
                DataTable dtTable = new DataTable();
                daAdapter.SelectCommand = scdCommand;
                daAdapter.Fill(dtTable);

                return(dtTable);
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
            finally
            {
                daAdapter.Dispose();
                scdCommand.Dispose();
            }
        }
Exemplo n.º 4
0
 public object ExecuteScalar(DbCommand scdCommand, DbConnection Conn)
 {
     try
     {
         scdCommand.Connection = Conn;
         return(scdCommand.ExecuteScalar());
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 5
0
 public object GetParameterValue(DbCommand command,
                                 string name)
 {
     try
     {
         return(command.Parameters[BuildParameterName(name)].Value);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 6
0
 public DbParameter createParameter(DbCommand command, string name, DbType type, object value, int size)
 {
     try
     {
         DbParameter p = createParameter(command, name, type, value);
         p.Size = size;
         return(p);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 7
0
 public void AddOutParameter(DbCommand command,
                             string name,
                             DbType dbType,
                             int size)
 {
     try
     {
         AddParameter(command, name, dbType, size, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default, DBNull.Value);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 8
0
        private DbProviderFactory GetFactoty()
        {
            try
            {
                string strProviderName = ConfigurationManager.ConnectionStrings[ConnectionStringName].ProviderName;

                DbProviderFactory factory = DbProviderFactories.GetFactory(strProviderName);

                return(factory);
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
        }
Exemplo n.º 9
0
 public DbParameter createOutputParameter(DbCommand command, string name, DbType type)
 {
     try
     {
         DbParameter p = command.CreateParameter();
         p.ParameterName = name;
         p.DbType        = type;
         p.Direction     = ParameterDirection.ReturnValue;
         return(p);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 10
0
        protected DbParameter CreateParameter(string name)
        {
            try
            {
                DbProviderFactory factory = this.GetFactoty();

                DbParameter param = factory.CreateParameter();
                param.ParameterName = BuildParameterName(name);

                return(param);
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
        }
Exemplo n.º 11
0
 public void AddParameter(DbCommand command,
                          string name,
                          DbType dbType,
                          ParameterDirection direction,
                          string sourceColumn,
                          DataRowVersion sourceVersion,
                          object value)
 {
     try
     {
         AddParameter(command, name, dbType, 0, direction, false, 0, 0, sourceColumn, sourceVersion, value);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 12
0
        public object ExecuteScalar(DbCommand scdCommand)
        {
            try
            {
                DbConnection Conn = Conexao.abrirConexao();
                scdCommand.Connection = Conn;

                return(scdCommand.ExecuteScalar());
            }
            catch (Exception ex)
            {
                int numeroErro = LogEventError.Write(ex.Message);
                throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
            }
            finally
            {
                Conexao.fecharConexao(scdCommand.Connection);
                scdCommand.Dispose();
            }
        }
Exemplo n.º 13
0
 public DbDataReader ExecuteReader(DbCommand scdCommand)
 {
     try
     {
         OracleCommand    cm = (OracleCommand)scdCommand;
         OracleConnection cn = (OracleConnection)Conexao.abrirConexao();
         cm.Connection = cn;
         cm.Parameters.Add(CursorRetorno, OracleType.Cursor).Direction = ParameterDirection.Output;
         return(cm.ExecuteReader(CommandBehavior.CloseConnection));
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
     finally
     {
         //Conexao.fecharConexao(scdCommand.Connection);
         //scdCommand.Dispose();
     }
 }
Exemplo n.º 14
0
 public int InserirOracle(DbCommand scdCommand)
 {
     try
     {
         DbConnection Conn = Conexao.abrirConexao();
         scdCommand.Connection = Conn;
         this.AddOutParameter(scdCommand, "IDENTITY", DbType.Int32, 4);
         scdCommand.ExecuteNonQuery();
         return((int)scdCommand.Parameters["IDENTITY"].Value);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
     finally
     {
         Conexao.fecharConexao(scdCommand.Connection);
         scdCommand.Dispose();
     }
 }
Exemplo n.º 15
0
 public int ExecuteNonQuery(DbCommand scdCommand, DbTransaction Trans)
 {
     if (Trans != null)
     {
         try
         {
             scdCommand.Connection  = Trans.Connection;
             scdCommand.Transaction = Trans;
             return(scdCommand.ExecuteNonQuery());
         }
         catch (DbException ex)
         {
             // TrataException.SetError(ex);    //AAS - 2008-09-23
             int numeroErro = LogEventError.Write(ex.Message);
             throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
         }
     }
     else
     {
         return(this.ExecuteNonQuery(scdCommand));
     }
 }
Exemplo n.º 16
0
 protected DbParameter CreateParameter(string name,
                                       DbType dbType,
                                       int size,
                                       ParameterDirection direction,
                                       bool nullable,
                                       byte precision,
                                       byte scale,
                                       string sourceColumn,
                                       DataRowVersion sourceVersion,
                                       object value)
 {
     try
     {
         DbParameter param = CreateParameter(name);
         ConfigureParameter(param, name, dbType, size, direction, nullable, precision, scale, sourceColumn, sourceVersion, value);
         return(param);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 17
0
 public virtual void AddParameter(DbCommand command,
                                  string name,
                                  DbType dbType,
                                  int size,
                                  ParameterDirection direction,
                                  bool nullable,
                                  byte precision,
                                  byte scale,
                                  string sourceColumn,
                                  DataRowVersion sourceVersion,
                                  object value)
 {
     try
     {
         DbParameter parameter = CreateParameter(name, dbType, size, direction, nullable, precision, scale, sourceColumn, sourceVersion, value);
         command.Parameters.Add(parameter);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception("Ocorreu um erro ao tentar acessar o Banco de Dados. Err.ID " + numeroErro);
     }
 }
Exemplo n.º 18
0
 public DataTable ExecuteOracleDataTable(DbCommand scdCommand)
 {
     try
     {
         OracleCommand    cm = (OracleCommand)scdCommand;
         OracleConnection cn = (OracleConnection)Conexao.abrirConexao();
         cm.Connection = cn;
         cm.Parameters.Add(CursorRetorno, OracleType.Cursor).Direction = ParameterDirection.Output;
         OracleDataReader dr = cm.ExecuteReader(CommandBehavior.CloseConnection);
         DataTable        dt = new DataTable();
         dt.Load(dr);
         return(dt);
     }
     catch (Exception ex)
     {
         int numeroErro = LogEventError.Write(ex.Message);
         throw new Exception(string.Format("Ocorreu um erro número:{0}. Descrição: {1}", numeroErro, ex.Message));
     }
     finally
     {
         Conexao.fecharConexao(scdCommand.Connection);
         scdCommand.Dispose();
     }
 }