public async Task BeginTransactionAsync() { /*~~~~~~~~~~~~~~~ SQL SERVER ~~~~~~~~~~~~~~~*/ /* Dispose */ if (_transaction != null) { await _transaction.RollbackAsync(); await _transaction.DisposeAsync(); } if (_connection != null) { await _connection.CloseAsync(); await _connection.DisposeAsync(); } /* Create */ _connection = new SqlConnection(_config.SqlServerConnectionString); await _connection.OpenAsync(); var dbTransaction = await _connection.BeginTransactionAsync(); _transaction = (SqlTransaction)dbTransaction; }
public async Task <string> ExecSqlAsync(List <ParamSql> lst) { string result; try { using (this.conn = new SqlConnection(this._connectionString)) { bool flag = this.conn.State != ConnectionState.Open; if (flag) { await this.conn.OpenAsync(); } SqlTransaction sqlTransaction = this.conn.BeginTransaction(); try { this.cmd = new SqlCommand(); this.cmd.CommandType = CommandType.Text; this.cmd.Connection = this.conn; this.cmd.Transaction = sqlTransaction; foreach (ParamSql paramSql in lst) { this.cmd.CommandText = paramSql.Sql; foreach (SqlHelperParameter sqlHelperParameter in paramSql.Params) { this.cmd.Parameters.Add(this.GetParameter(sqlHelperParameter)); } await this.cmd.ExecuteNonQueryAsync(); } await sqlTransaction.CommitAsync(); result = string.Empty; } catch (Exception ex) { await sqlTransaction.RollbackAsync(); result = ex.Message; } finally { await sqlTransaction.DisposeAsync(); await this.cmd.DisposeAsync(); await this.conn.CloseAsync(); } } } catch (Exception ex2) { result = ex2.Message; } return(result); }
public async Task <string> ExecSqlAsync(ArrayList sqlList) { string result; using (this.conn = new SqlConnection(this._connectionString)) { bool flag = this.conn.State != ConnectionState.Open; if (flag) { await this.conn.OpenAsync(); } bool flag2 = sqlList.Count == 1; if (flag2) { result = await this.ExecSqlAsync(sqlList[0].ToString()); } else { SqlTransaction sqlTransaction = this.conn.BeginTransaction(); try { this.cmd = new SqlCommand(); this.cmd.CommandType = CommandType.Text; this.cmd.Connection = this.conn; this.cmd.Transaction = sqlTransaction; foreach (object obj in sqlList) { string commandText = (string)obj; this.cmd.CommandText = commandText; await this.cmd.ExecuteNonQueryAsync(); } await sqlTransaction.CommitAsync(); result = string.Empty; } catch (Exception ex) { await sqlTransaction.RollbackAsync(); result = ex.Message; } finally { await sqlTransaction.DisposeAsync(); } } } return(result); }
public ValueTask DisposeAsync() { connection?.DisposeAsync(); transaction?.DisposeAsync(); return(new ValueTask()); }