当前位置: 首页>>代码示例>>C#>>正文


C# DBConnection.CommitTransaction方法代码示例

本文整理汇总了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();
         }
     }
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:45,代码来源:SQLTraceDb.cs

示例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);
     }
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:74,代码来源:DataHelper.cs

示例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);
 }
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:34,代码来源:SQLDataEngine.cs

示例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;
            }
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:37,代码来源:AppRequestState.cs


注:本文中的DBConnection.CommitTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。