本文整理汇总了C#中DBConnection.CommitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# DBConnection.CommitTransaction方法的具体用法?C# DBConnection.CommitTransaction怎么用?C# DBConnection.CommitTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection.CommitTransaction方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveTraceToDb
public override void SaveTraceToDb()
{
LoggingService.Info("开始保存痕迹记录...");
DBConnection connection = new DBConnection(base.SMDataSource);
connection.Open();
try
{
if (LoggingService.IsDebugEnabled)
{
LoggingService.DebugFormatted("共有修改或添加的痕迹记录:{0}条,删除记录:{1}条", new object[] { this.TraceTable.Rows.Count, (this._RecDelTable == null) ? 0 : this._RecDelTable.Rows.Count });
}
DbTransaction transaction = connection.BeginTrasaction() as DbTransaction;
DbDataAdapter adapter = this.TraceTable.ExtendedProperties["da"] as DbDataAdapter;
adapter.InsertCommand.Connection = connection.Connection as DbConnection;
adapter.InsertCommand.Transaction = transaction;
adapter.Update(this.TraceTable);
if (TraceUtil.CanTraceLevel(TraceLevel.Deleted))
{
DbDataAdapter adapter2 = this._RecDelTable.ExtendedProperties["da"] as DbDataAdapter;
adapter2.InsertCommand.Connection = connection.Connection as DbConnection;
adapter2.InsertCommand.Transaction = transaction;
adapter2.Update(this._RecDelTable);
}
connection.CommitTransaction();
}
catch (DbException exception)
{
connection.RollBackTransaction();
string dataSetName = "TraceDb" + DateTimeHelper.GetNow().ToString();
DataSet set = new DataSet(dataSetName);
set.Tables.Add(this.TraceTable);
set.Tables.Add(this._RecDelTable);
set.WriteXml(Environment.CurrentDirectory + @"\" + dataSetName + ".xml");
throw new DataFormException("数据修改日志记录保存不成功能(数据已成功能保存)!", exception);
}
finally
{
connection.Close();
this.TraceTable.Rows.Clear();
if (this._RecDelTable != null)
{
this._RecDelTable.Rows.Clear();
}
}
}
示例2: Delete
public static void Delete(IDictionary<DAODataSet, string> deletes)
{
Exception exception;
try
{
string str = string.Empty;
DAODataSet key = null;
List<string> list = new List<string>(deletes.Count);
List<string> list2 = new List<string>(deletes.Count);
foreach (KeyValuePair<DAODataSet, string> pair in deletes)
{
key = pair.Key;
foreach (DAODataTable table in key.DAODataTables)
{
str = str + "delete from " + table.Name + " where ";
if (table.Level)
{
str = str + table.RelKey;
}
else
{
str = str + table.Key;
list.Add(table.Name);
list2.Add(pair.Value.ToString().Replace("'", ""));
}
str = str + " in (" + pair.Value + ");\r";
}
}
if (str != string.Empty)
{
DBConnection connection = new DBConnection(key.DataSource);
connection.Open();
IDbTransaction transaction = connection.BeginTrasaction();
try
{
IDbCommand command = connection.Connection.CreateCommand();
command.Transaction = transaction;
command.CommandText = str;
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
connection.CommitTransaction();
}
catch (Exception exception1)
{
exception = exception1;
connection.RollBackTransaction();
throw exception;
}
finally
{
connection.Close();
}
try
{
ITraceDb traceDB = GetTraceDB(key.DataSource);
if (TraceUtil.CanTraceLevel(TraceLevel.Deleted) && (traceDB != null))
{
traceDB.TraceOuterRemove(list.ToArray(), list2.ToArray(), "经由系统(可能是前台工作流完全删除)操作删除进行的记录,注意它并没有对子表的删除进行记录.");
traceDB.SaveTraceToDb();
}
}
catch (Exception exception2)
{
exception = exception2;
log.Error("进行删除的痕迹记录出错:", exception);
}
}
}
catch (Exception exception3)
{
exception = exception3;
throw new DataFormException("delete data raise error!", exception);
}
}
示例3: SaveDataToSQlDB
private void SaveDataToSQlDB(SMDataSource smDS, ref DataTable dt)
{
DBConnection connection = new DBConnection(smDS);
connection.Open();
try
{
IDbTransaction transaction = connection.BeginTrasaction();
DataTable dataTable = dt;
if (dataTable.GetChanges() != null)
{
string strSelect = (string) dataTable.ExtendedProperties["selectsql"];
DbDataAdapter adapter = connection.GetDataAdapter(strSelect, true, true, true);
try
{
adapter.Update(dataTable);
}
catch (DBConcurrencyException exception)
{
throw new DataFormException(exception.Message, exception);
}
}
connection.CommitTransaction();
}
catch (Exception exception2)
{
connection.RollBackTransaction();
throw exception2;
}
finally
{
connection.Close();
}
dt = this.RefreshDataset(smDS, dt);
}
示例4: cleanUpDatabaseConnection
private void cleanUpDatabaseConnection( DBConnection connection )
{
// Keep the connection initialized during cleanup to accommodate commit-time validation methods.
try {
try {
if( !DataAccessStatics.DatabaseShouldHaveAutomaticTransactions( connection.DatabaseInfo ) )
return;
try {
if( !transactionMarkedForRollback )
connection.CommitTransaction();
}
catch {
// Modifying this boolean here means that the order in which connections are cleaned up matters. Not modifying it here means
// possibly committing things to secondary databases that shouldn't be committed. We've decided that the primary connection
// is the most likely to have these errors, and is cleaned up first, so modifying this boolean here will yield the best results
// until we implement a true distributed transaction model with two-phase commit.
transactionMarkedForRollback = true;
throw;
}
finally {
if( transactionMarkedForRollback )
connection.RollbackTransaction();
}
}
finally {
connection.Close();
}
}
finally {
if( connection.DatabaseInfo.SecondaryDatabaseName.Any() )
secondaryDatabasesWithInitializedConnections.Remove( connection.DatabaseInfo.SecondaryDatabaseName );
else
primaryDatabaseConnectionInitialized = false;
}
}