DBHelper

/// <summary>
/// Execute command
/// </summary>
/// <param name="sqlString"></param>
public int ExecuteSql(string sqlString)
{
SqlConnection connection = GetConnection();
SqlCommand command = new SqlCommand(sqlString, connection);
SqlTransaction transaction = null;
try
{
connection.Open();
transaction = connection.BeginTransaction("Transaction");
command.CommandTimeout = 600;
command.Transaction = transaction;

DateTime startTime = DateTime.Now;
int iAffected = command.ExecuteNonQuery();
Log.WriteTimeOutLog(startTime, "[SQL]" + command.CommandText);

transaction.Commit();

return iAffected;
}
catch (Exception ex)
{
transaction.Rollback();
throw ex;
}
finally
{
connection.Close();
}
}

原文地址:https://www.cnblogs.com/kevin1988/p/3668009.html