/// <summary> /// Creates a DataAdapter on the given query-statement (Handled wrapper). /// </summary> /// <param name="sqlQuery">SQL-query</param> /// <param name="parameters">Query-parameters</param> /// <returns>DataAdapter of the given query-statement</returns> private DataAdapter GetDataAdapterHandled(string sqlQuery, params object[] parameters) { try { DataAdapter dbResult = GetDataAdapterImplement(sqlQuery, parameters); LastErrorCode = WrapSQLErrorCode.Success; return(dbResult); } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.OperationDataAdapterFailed; throw new WrapSQLException("The operation \"GetDataAdapter\" failed.", ex); } }
/// <summary> /// Executes a query-statement (Handled wrapper). /// </summary> /// <param name="sqlQuery">SQL-query</param> /// <param name="parameters">Query-parameters</param> /// <returns>DataReader fetching the query-results</returns> private DbDataReader ExecuteQueryManaged(string sqlQuery, params object[] parameters) { try { DbDataReader dbResult = ExecuteQueryImplement(sqlQuery, parameters); LastErrorCode = WrapSQLErrorCode.Success; return(dbResult); } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.OperationQueryFailed; throw new WrapSQLException("The operation \"ExecuteQuery\" failed.", ex); } }
/// <summary> /// Creates a DataTable with the results of a query-statement (Handled wrapper). /// </summary> /// <param name="sqlQuery">SQL-query</param> /// <param name="parameters">Query-parameters</param> /// <returns>Results of a query-statement</returns> private DataTable CreateDataTableHandled(string sqlQuery, params object[] parameters) { try { DataTable dbResult = CreateDataTableImplement(sqlQuery, parameters); LastErrorCode = WrapSQLErrorCode.Success; return(dbResult); } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.OperationDataTableFailed; throw new WrapSQLException("The operation \"CreateDataTable\" failed.", ex); } }
/// <summary> /// Executes a execute-scalar statement (Handled wrapper). /// </summary> /// <typeparam name="T">Target-datatype of the result</typeparam> /// <param name="sqlQuery">SQL-query</param> /// <param name="aCon">Manage connection states (AutoConnect)</param> /// <param name="parameters">Query-parameters</param> /// <returns>Result of the scalar-query</returns> private T ExecuteScalarHandled <T>(string sqlQuery, bool aCon, params object[] parameters) { try { T dbResult = ExecuteScalarImplement <T>(sqlQuery, aCon, parameters); LastErrorCode = WrapSQLErrorCode.Success; return(dbResult); } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.OperationScalarFailed; throw new WrapSQLException("The operation \"ExecuteScalar\" failed.", ex); } }
/// <summary> /// Executes a non-query statement (Handled wrapper). /// </summary> /// <param name="sqlQuery">SQL-query</param> /// <param name="aCon">Manage connection states (AutoConnect)</param> /// <param name="parameters">Query-parameters</param> /// <returns>NonQuery result</returns> private int ExecuteNonQueryHandled(string sqlQuery, bool aCon, params object[] parameters) { try { int dbResult = ExecuteNonQueryImplement(sqlQuery, aCon, parameters); LastErrorCode = WrapSQLErrorCode.Success; return(dbResult); } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.OperationNonQueryFailed; throw new WrapSQLException("The operation \"ExecuteNonQuery\" failed.", ex); } }
/// <summary> /// Terminates a transaction. /// </summary> public void TransactionRollback() { try { transaction.Rollback(); transactionActive = false; LastErrorCode = WrapSQLErrorCode.Success; } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.TransactionRollbackFailed; throw new WrapSQLException("Transaction could not be rolled back.", ex); } }
/// <summary> /// Commits a transaction. /// </summary> public void TransactionCommit() { try { transaction.Commit(); transactionActive = false; LastErrorCode = WrapSQLErrorCode.Success; } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.TransactionCommitFailed; throw new WrapSQLException("Transaction could not be commited.", ex); } }
/// <summary> /// Starts a transaction. /// </summary> public void TransactionBegin() { try { transactionActive = true; transaction = Connection.BeginTransaction(); LastErrorCode = WrapSQLErrorCode.Success; } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.TransactionBeginFailed; throw new WrapSQLException("Transaction could not be started.", ex); } }
/// <summary> /// Closes the SQL-Connection, if the connection is open. /// </summary> public virtual void Close() { try { if (this.Connection.State == ConnectionState.Open) { Connection.Close(); } LastErrorCode = WrapSQLErrorCode.Success; } catch (Exception ex) { LastErrorCode = WrapSQLErrorCode.ConnectionCloseFailed; throw new WrapSQLException("Connection could not be closed.", ex); } }