public int ExecuteCommand(ISqlCommand sqlCommand) { if (sqlCommand == null) { throw new ArgumentNullException("sqlCommand"); } using (var connection = new SqlConnection(this.connectionString)) { try { connection.Open(); using (var command = sqlCommand.GetCommand()) { command.Connection = connection; command.CommandTimeout = 1000; ////string.Format(CultureInfo.InvariantCulture, "Executing Database command '{0}'.", command.CommandText).LogAsInformation(); return(command.ExecuteNonQuery()); } } catch (Exception exception) { this.logger.LogError(exception.Message); throw; } } }
public async Task <IDataReader> ExecuteReaderAsync(ISqlCommand sqlCommand) { if (sqlCommand == null) { throw new ArgumentNullException("sqlCommand"); } var connection = new SqlConnection(this.connectionString); try { await connection.OpenAsync().ConfigureAwait(false); using (var command = sqlCommand.GetCommand()) { command.Connection = connection; var watch = new Stopwatch(); watch.Start(); var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection); watch.Stop(); this.logger.LogInformation("SQL query {0} was done in {1} ms.", new object[] { command.CommandText + " AdoNet Async", watch.ElapsedMilliseconds }); return(reader); } } catch (Exception exception) { if (connection.State != ConnectionState.Closed) { connection.Close(); } this.logger.LogError(exception.Message); throw; } }
public IDataReader ExecuteReader(ISqlCommand sqlCommand) { if (sqlCommand == null) { throw new ArgumentNullException("sqlCommand"); } var connection = new SqlConnection(this.connectionString); try { connection.Open(); using (var command = sqlCommand.GetCommand()) { command.Connection = connection; var watch = new Stopwatch(); watch.Start(); var reader = command.ExecuteReader(CommandBehavior.CloseConnection); watch.Stop(); this.logger.LogInformation("SQL query {0} was done in {1} ms.", new object[] { command.CommandText + " AdoNet", watch.ElapsedMilliseconds }); return reader; } } catch (Exception exception) { if (connection.State != ConnectionState.Closed) { connection.Close(); } this.logger.LogError(exception.Message); throw; } }
public int ExecuteCommand(ISqlCommand sqlCommand, TransactionScopeOption transactionScopeOption) { if (sqlCommand == null) { throw new ArgumentNullException("sqlCommand"); } int rowsAffected; using (var scope = new TransactionScope(transactionScopeOption)) { try { using (var sqlConnection = new SqlConnection(this.connectionString)) { sqlConnection.Open(); using (var command = sqlCommand.GetCommand()) { command.Connection = sqlConnection; ////string.Format(CultureInfo.InvariantCulture, "Executing Database command '{0}'.", command.CommandText).LogAsInformation(); rowsAffected = command.ExecuteNonQuery(); } } scope.Complete(); } catch (Exception exception) { this.logger.LogError(exception.Message); throw; } } return(rowsAffected); }
public int ExecuteCommand(ISqlCommand sqlCommand, TransactionScopeOption transactionScopeOption) { if (sqlCommand == null) { throw new ArgumentNullException("sqlCommand"); } int rowsAffected; using (var scope = new TransactionScope(transactionScopeOption)) { try { using (var sqlConnection = new SqlConnection(this.connectionString)) { sqlConnection.Open(); using (var command = sqlCommand.GetCommand()) { command.Connection = sqlConnection; ////string.Format(CultureInfo.InvariantCulture, "Executing Database command '{0}'.", command.CommandText).LogAsInformation(); rowsAffected = command.ExecuteNonQuery(); } } scope.Complete(); } catch (Exception exception) { this.logger.LogError(exception.Message); throw; } } return rowsAffected; }
public int ExecuteCommand(ISqlCommand sqlCommand) { if (sqlCommand == null) { throw new ArgumentNullException("sqlCommand"); } using (var connection = new SqlConnection(this.connectionString)) { try { connection.Open(); using (var command = sqlCommand.GetCommand()) { command.Connection = connection; command.CommandTimeout = 1000; ////string.Format(CultureInfo.InvariantCulture, "Executing Database command '{0}'.", command.CommandText).LogAsInformation(); return command.ExecuteNonQuery(); } } catch (Exception exception) { this.logger.LogError(exception.Message); throw; } } }