本文整理汇总了C#中IDbTransaction.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IDbTransaction.Dispose方法的具体用法?C# IDbTransaction.Dispose怎么用?C# IDbTransaction.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbTransaction
的用法示例。
在下文中一共展示了IDbTransaction.Dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateQueuedAndHistoryForSchedule
/// <summary>
/// Creates the queue and history records for the given schedule.
/// </summary>
/// <param name="scheduleId">The ID of the schedule records are being created for.</param>
/// <param name="scheduleDate">The schedule date records are being created for.</param>
/// <param name="queued">The queued records to create.</param>
/// <param name="history">The history records to create.</param>
/// <param name="transaction">The transaction to use, if applicable.</param>
/// <returns>The number of records created.</returns>
public int CreateQueuedAndHistoryForSchedule(long scheduleId, DateTime scheduleDate, IEnumerable<QueueRecord> queued, IEnumerable<HistoryRecord> history, IDbTransaction transaction)
{
int created = 0;
bool commitRollback = false;
if (transaction == null)
{
commitRollback = true;
transaction = this.BeginTransaction();
}
try
{
const string InsertQueuedSql =
@"INSERT INTO [BlueCollarQueue]([ApplicationName],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber])
VALUES(@ApplicationName,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber);";
const string InsertHistorySql =
@"INSERT INTO [BlueCollarHistory]([ApplicationName],[WorkerId],[ScheduleId],[QueueName],[JobName],[JobType],[Data],[QueuedOn],[TryNumber],[StartedOn],[Status],[Exception],[FinishedOn])
VALUES (@ApplicationName,@WorkerId,@ScheduleId,@QueueName,@JobName,@JobType,@Data,@QueuedOn,@TryNumber,@StartedOn,@StatusString,@Exception,@FinishedOn);";
if (queued != null && queued.Count() > 0)
{
created += this.connection.Execute(InsertQueuedSql, queued, transaction, null, null);
}
if (history != null && history.Count() > 0)
{
created += this.connection.Execute(InsertHistorySql, history, transaction, null, null);
}
if (commitRollback)
{
transaction.Commit();
}
}
catch
{
if (commitRollback)
{
transaction.Rollback();
}
throw;
}
finally
{
if (commitRollback)
{
transaction.Dispose();
}
}
return created;
}
示例2: DisposeTransaction
/// <summary>
/// 子类实现此方法释放指定的事务。
/// </summary>
/// <returns></returns>
protected virtual void DisposeTransaction(IDbTransaction tran)
{
tran.Dispose();
}
示例3:
/// <summary>
/// Закрыть транзакцию
/// </summary>
/// <param name="transaction"></param>
public static void СommitTransaction(IDbTransaction transaction) {
if (transaction != null) {
var v_storedConn = transaction.Connection;
transaction.Commit();
transaction.Dispose();
if (v_storedConn != null) {
v_storedConn.Close();
v_storedConn.Dispose();
}
}
}
示例4: RollbackTransaction
/// <summary>
/// Откатить транзакцию
/// </summary>
/// <param name="trans"></param>
public static void RollbackTransaction(IDbTransaction trans) {
if (trans != null) {
var v_storedConn = trans.Connection;
try {
trans.Rollback();
} catch (InvalidOperationException) { }
trans.Dispose();
if (v_storedConn != null) {
v_storedConn.Close();
v_storedConn.Dispose();
}
}
}
示例5: Execute
/// <summary>
/// The execute.
/// </summary>
/// <param name="dbfunctionType">
/// The dbfunction type.
/// </param>
/// <param name="operationName">
/// The operation name.
/// </param>
/// <param name="parameters">
/// The parameters.
/// </param>
/// <param name="result">
/// The result.
/// </param>
/// <param name="transaction"></param>
/// <returns>
/// The execute.
/// </returns>
public virtual bool Execute(
DbFunctionType dbfunctionType,
[NotNull] string operationName,
[NotNull] IEnumerable<KeyValuePair<string, object>> parameters,
[CanBeNull] out object result,
IDbTransaction transaction = null)
{
if (this.IsSupportedOperation(operationName))
{
this._sqlMessages.Clear();
bool createdTransaction = transaction == null;
try
{
if (transaction == null)
{
transaction = this.DbAccess.BeginTransaction();
}
if (transaction.Connection is SqlConnection)
{
var sqlConnection = transaction.Connection as SqlConnection;
sqlConnection.FireInfoMessageEventOnUserErrors = true;
sqlConnection.InfoMessage += new SqlInfoMessageEventHandler(this.sqlConnection_InfoMessage);
var operationSuccessful = this.RunOperation(sqlConnection, transaction, dbfunctionType, operationName, parameters, out result);
if (createdTransaction && operationSuccessful)
{
transaction.Commit();
}
return operationSuccessful;
}
}
finally
{
if (createdTransaction && transaction != null)
{
transaction.Dispose();
}
}
}
result = null;
return false;
}
示例6: BeginTransaction
public void BeginTransaction(IsolationLevel isolationLevel)
{
if (IsOpen) {
throw new InvalidOperationException("Transaction already open.");
}
//Open connection
try {
connection.Open();
transaction = this.connection.BeginTransaction(isolationLevel);
transactionOpen = true;
} catch (Exception) {
// in the event of an error, close the connection and destroy the transaction object.
if (connection != null) {
connection.Close();
}
if (transaction != null) {
transaction.Dispose();
}
transactionOpen = false;
throw;
}
}
示例7: CloseConnection
public void CloseConnection(IDbTransaction tran)
{
if (tran.Connection != null && tran.Connection.State != ConnectionState.Closed)
{
try
{
tran.Connection.Close();
tran.Connection.Dispose();
}
finally
{
tran.Dispose();
}
}
}
示例8: EndUpdate
public void EndUpdate(IDbTransaction trans)
{
trans.Commit();
trans.Dispose();
m_conn.Close();
m_conn = null;
}
示例9: CancelUpdate
public void CancelUpdate(IDbTransaction trans)
{
trans.Rollback();
trans.Dispose();
m_conn.Close();
m_conn = null;
}