System.Data.Common.DbConnection.BeginTransaction(System.Data.IsolationLevel)

Here are the examples of the csharp api class System.Data.Common.DbConnection.BeginTransaction(System.Data.IsolationLevel) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

52 Examples 7

1. Example

Project: Glimpse
Source File: GlimpseDbConnection.cs
View license
protected override DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
        {
            return new GlimpseDbTransaction(InnerConnection.BeginTransaction(isolationLevel), this);
        }

2. Example

Project: Dos.ORM
Source File: Database.cs
View license
private IDbTransaction BeginTransaction(DbConnection connection, IsolationLevel il)
        {
            return connection.BeginTransaction(il);
        }

3. Example

Project: Dos.ORM
Source File: Database.cs
View license
private IDbTransaction BeginTransaction(DbConnection connection, IsolationLevel il)
        {
            return connection.BeginTransaction(il);
        }

4. Example

Project: Dos.ORM
Source File: Database.cs
View license
private IDbTransaction BeginTransaction(DbConnection connection, IsolationLevel il)
        {
            return connection.BeginTransaction(il);
        }

5. Example

Project: StarryEyes
Source File: SharedConnection.cs
View license
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            return _baseConnection.BeginTransaction(isolationLevel);
        }

6. Example

Project: ALinq
Source File: Connection.cs
View license
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            var sourceTran = source.BeginTransaction(isolationLevel);
            //return new Transaction(sourceTran, this);
            return sourceTran;
        }

7. Example

Project: NServiceKit
Source File: ProfiledDbConnection.cs
View license
protected override DbTransaction BeginDbTransaction(System.Data.IsolationLevel isolationLevel)
        {
            return new ProfiledDbTransaction(_conn.BeginTransaction(isolationLevel), this);
        }

8. Example

Project: Radical
Source File: DbConnectionWrapper.cs
View license
protected override DbTransaction BeginDbTransaction( IsolationLevel isolationLevel )
        {
            return this.WrappedConnection.BeginTransaction( isolationLevel );
        }

9. Example

Project: DNTProfiler
Source File: ProfiledDbConnection.cs
View license
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            return new ProfiledDbTransaction(InnerConnection.BeginTransaction(isolationLevel), this, _profiler);
        }

10. Example

Project: EDDiscovery
Source File: SQLiteConnectionED.cs
View license
public override DbTransaction BeginTransaction(IsolationLevel isolevel)
        {
            // Take the transaction lock before beginning the
            // transaction to avoid a deadlock
            AssertThreadOwner();
            _transactionLock.OpenWriter();
            return new SQLiteTransactionED<TConn>(_cn.BeginTransaction(isolevel), _transactionLock);
        }

11. Example

Project: nesper
Source File: BaseDbDriver.cs
View license
protected virtual void SetTransactionIsolation( DbConnection connection, IsolationLevel? isolationLevel )
        {
			try
			{
				if (isolationLevel != null)
				{
                    // Begin a transaction to provide the proper isolation.  Need to ensure
                    // that the transaction is properly committed upon completion since we
                    // do not have auto-commit handled.
                    connection.BeginTransaction(isolationLevel.Value);
				}
			}
			catch (DbException ex)
			{
				throw new DatabaseConfigException(
                    "Error setting transaction isolation level to " + isolationLevel +
                    " on connection with detail " + GetDetail(ex), ex);
			}
        }

12. Example

Project: nesper
Source File: BaseDbDriver.cs
View license
protected virtual void SetTransactionIsolation( DbConnection connection, IsolationLevel? isolationLevel )
        {
			try
			{
				if (isolationLevel != null)
				{
                    // Begin a transaction to provide the proper isolation.  Need to ensure
                    // that the transaction is properly committed upon completion since we
                    // do not have auto-commit handled.
                    connection.BeginTransaction(isolationLevel.Value);
				}
			}
			catch (DbException ex)
			{
				throw new DatabaseConfigException(
                    "Error setting transaction isolation level to " + isolationLevel +
                    " on connection with detail " + GetDetail(ex), ex);
			}
        }

13. Example

Project: WPFCrudControl
Source File: UnitOfWork.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
        {
            _objectContext = ((IObjectContextAdapter)_dataContext).ObjectContext;
            if (_objectContext.Connection.State != ConnectionState.Open)
            {
                _objectContext.Connection.Open();
            }

            _transaction = _objectContext.Connection.BeginTransaction(isolationLevel);
        }

14. Example

Project: efprs
Source File: UnitOfWork.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel)
        {
            if (_transaction != null)
            {
                throw new ApplicationException("Cannot begin a new transaction while an existing transaction is still running. " +
                                                "Please commit or rollback the existing transaction before starting a new one.");
            }
            OpenConnection();
            _transaction = ((IObjectContextAdapter)_dbContext).ObjectContext.Connection.BeginTransaction(isolationLevel);
        }

15. Example

Project: efprs
Source File: UnitOfWork.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel)
        {
            if (_transaction != null)
            {
                throw new ApplicationException("Cannot begin a new transaction while an existing transaction is still running. " +
                                                "Please commit or rollback the existing transaction before starting a new one.");
            }
            OpenConnection();
            _transaction = _objectContext.Connection.BeginTransaction(isolationLevel);
        }

16. Example

Project: efprs
Source File: UnitOfWork.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel)
        {
            if (_transaction != null)
            {
                throw new ApplicationException("Cannot begin a new transaction while an existing transaction is still running. " +
                                                "Please commit or rollback the existing transaction before starting a new one.");
            }
            OpenConnection();
            _transaction = ((IObjectContextAdapter)_dbContext).ObjectContext.Connection.BeginTransaction(isolationLevel);
        }

17. Example

Project: Dos.ORM
Source File: Database.cs
View license
public DbTransaction BeginTransaction(IsolationLevel il)
        {
            return GetConnection(true).BeginTransaction(il);
        }

18. Example

Project: Dos.ORM
Source File: Database.cs
View license
public DbTransaction BeginTransaction(IsolationLevel il)
        {
            return GetConnection(true).BeginTransaction(il);
        }

19. Example

Project: Dos.ORM
Source File: Database.cs
View license
public DbTransaction BeginTransaction(IsolationLevel il)
        {
            return GetConnection(true).BeginTransaction(il);
        }

20. Example

Project: URF
Source File: UnitOfWork.cs
View license
public virtual void BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.Unspecified)
        {
            var objectContext = ((IObjectContextAdapter) _context).ObjectContext;
            if (objectContext.Connection.State != ConnectionState.Open)
            {
                objectContext.Connection.Open();
            }
            Transaction = objectContext.Connection.BeginTransaction(isolationLevel);
        }

21. Example

Project: Lidarr
Source File: DataMapper.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel)
        {
            OpenConnection();
            DbTransaction trans = Command.Connection.BeginTransaction(isolationLevel);
            Command.Transaction = trans;
        }

22. Example

View license
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
    {
      if (isolationLevel == IsolationLevel.Unspecified)
        return BeginTransaction();
      return BeginTransaction(isolationLevel);
    }

23. Example

Project: Radarr
Source File: DataMapper.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel)
        {
            OpenConnection();
            DbTransaction trans = Command.Connection.BeginTransaction(isolationLevel);
            Command.Transaction = trans;
        }

24. Example

Project: framework
Source File: Transaction.cs
View license
public void Start()
            {
                if (!Started)
                {
                    Connection = Connector.Current.CreateConnection();

                    Connection.Open();
                    Transaction = Connection.BeginTransaction(IsolationLevel ?? Connector.Current.IsolationLevel);
                    Started = true;
                }
            }

25. Example

Project: Sonarr
Source File: DataMapper.cs
View license
public void BeginTransaction(IsolationLevel isolationLevel)
        {
            OpenConnection();
            DbTransaction trans = Command.Connection.BeginTransaction(isolationLevel);
            Command.Transaction = trans;
        }

26. Example

Project: YAFNET
Source File: IDbAccessExtensions.cs
View license
public static IDbTransaction BeginTransaction([NotNull] this IDbAccess dbAccess, IsolationLevel isolationLevel = IsolationLevel.ReadUncommitted)
        {
            CodeContracts.VerifyNotNull(dbAccess, "dbAccess");

            return dbAccess.CreateConnectionOpen().BeginTransaction(isolationLevel);
        }

27. Example

View license
public static DbTransaction BeginTransaction(this ObjectContext context, IsolationLevel isolationLevel = IsolationLevel.Unspecified)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (context.Connection.State != ConnectionState.Open)
                context.Connection.Open();

            return context.Connection.BeginTransaction(isolationLevel);
        }

28. Example

View license
public static DbTransaction BeginTransaction(this Database database, System.Data.IsolationLevel isolationLevel)
        {
            return database.GetOpenConnection().Connection.BeginTransaction(isolationLevel);
        }

29. Example

View license
public static DbTransaction BeginTransaction( this DbCommand dbCommand, IsolationLevel isolationLevel )
        {
            dbCommand.OpenConnection();

            DbTransaction transaction = dbCommand.Connection.BeginTransaction( isolationLevel );

            dbCommand.SetTransaction( transaction );

            return transaction;
        }

30. Example

Project: nlight
Source File: MockDataSource.cs
View license
private Task<DataSessionState> BeginSession(TransactionContext transactionContext)
		{
			if (transactionContext == null) throw new ArgumentNullException(nameof(transactionContext));

			return Task.Run(
				() =>
				{
					var state = new DataSessionState();
					WriteOperationTrace(state, "beginSession");

					WriteOperationTrace(state, "createConnection");
					state.Connection = new MockConnection { ConnectionString = $"MockDataSource.Id={this.Id},TransactionGroupName={this.TransactionGroupName}" };

					WriteOperationTrace(state, "openConnection");
					state.Connection.Open();

					if (transactionContext.Affinity != TransactionContextAffinity.NotSupported)
					{
						WriteOperationTrace(state, "beginTransaction");
						state.Transaction = state.Connection.BeginTransaction(transactionContext.IsolationLevel);
					}

					return state;
				});
		}

31. Example

Project: netTiers
Source File: TransactionManager.cs
View license
public void BeginTransaction( IsolationLevel isolationLevel )
		{
			if( IsOpen )
			{
				throw new InvalidOperationException( "Transaction already open." );
			}
			
			//Open connection
			try
			{
				this._connection.Open();
				this._transaction = this._connection.BeginTransaction( isolationLevel );
				this._transactionOpen = true;
			}
			catch ( Exception )
			{
				// in the event of an error, close the connection and destroy the transaction object.
                if ( this._connection != null ) 
				{
					this._connection.Close();
				}
				
                if ( this._transaction != null ) 
				{	
					this._transaction.Dispose();
				}
				
				this._transactionOpen = false;
				throw;
			}
		}

32. Example

Project: netTiers
Source File: TransactionManager.cs
View license
public void BeginTransaction( IsolationLevel isolationLevel )
		{
			if( IsOpen )
			{
				throw new InvalidOperationException( "Transaction already open." );
			}
			
			//Open connection
			try
			{
				this._connection.Open();
				this._transaction = this._connection.BeginTransaction( isolationLevel );
				this._transactionOpen = true;
			}
			catch ( Exception )
			{
				// in the event of an error, close the connection and destroy the transaction object.
                if ( this._connection != null ) 
				{
					this._connection.Close();
				}
				
                if ( this._transaction != null ) 
				{	
					this._transaction.Dispose();
				}
				
				this._transactionOpen = false;
				throw;
			}
		}

33. Example

View license
public virtual DbConnection GetDbConnection(string connectionString, bool rollbackOnScopeStatusFailure)
        {
            if (connectionString == null)
                throw new ArgumentNullException(nameof(connectionString));

            if (!_connections.ContainsKey(connectionString))
            {
                TDbConnection newConnection = new TDbConnection { ConnectionString = connectionString };
                newConnection.Open();
                DbTransaction transaction = newConnection.BeginTransaction(IsolationLevel.ReadCommitted);
                _connections.Add(connectionString, new DbConnectionAndTransactionPair(newConnection, transaction, rollbackOnScopeStatusFailure));
            }

            return _connections[connectionString].Connection;
        }

34. Example

View license
public virtual async Task<DbConnection> GetDbConnectionAsync(string connectionString, bool rollbackOnScopeStatusFailure,
            CancellationToken cancellationToken)
        {
            if (connectionString == null)
                throw new ArgumentNullException(nameof(connectionString));

            if (!_connections.ContainsKey(connectionString))
            {
                TDbConnection newDbConnection = new TDbConnection { ConnectionString = connectionString };
                await newDbConnection.OpenAsync(cancellationToken).ConfigureAwait(false);
                DbTransaction transaction = newDbConnection.BeginTransaction(IsolationLevel.ReadCommitted);
                _connections.Add(connectionString, new DbConnectionAndTransactionPair(newDbConnection, transaction, rollbackOnScopeStatusFailure));
            }

            return _connections[connectionString].Connection;
        }

35. Example

Project: Simple.Migrations
Source File: Migration.cs
View license
void IMigration<DbConnection>.RunMigration(MigrationRunData<DbConnection> data)
        {
            this.Connection = data.Connection;
            this.Logger = data.Logger;

            if (this.UseTransaction)
            {
                using (this.Transaction = this.Connection.BeginTransaction(IsolationLevel.Serializable))
                {
                    try
                    {
                        if (data.Direction == MigrationDirection.Up)
                            this.Up();
                        else
                            this.Down();

                        this.Transaction.Commit();
                    }
                    catch
                    {
                        this.Transaction?.Rollback();
                        throw;
                    }
                    finally
                    {
                        this.Transaction = null;
                    }
                }
            }
            else
            {
                if (data.Direction == MigrationDirection.Up)
                    this.Up();
                else
                    this.Down();
            }
        }

36. Example

Project: Cheezburger-BDSM
Source File: Importer.cs
View license
private void InternalUpgrade(bool forceFullUpdate)
        {
            FillMetaData();

            using (transatedConnection = connection)
            {
                using (transaction = connection.BeginTransaction(IsolationLevel.Serializable))
                {
                    ProcessUpgrade(forceFullUpdate);

                    foreach (var update in finalUpdates)
                        ExecuteNonQuery(update);

                    transaction.Commit();
                }
            }
        }

37. Example

Project: nhibernate-core
Source File: AdoTransaction.cs
View license
public void Begin(IsolationLevel isolationLevel)
		{
			using (session.BeginProcess())
			{
				if (begun)
				{
					return;
				}

				if (commitFailed)
				{
					throw new TransactionException("Cannot restart transaction after failed commit");
				}

				if (isolationLevel == IsolationLevel.Unspecified)
				{
					isolationLevel = session.Factory.Settings.IsolationLevel;
				}

				log.Debug(string.Format("Begin ({0})", isolationLevel));

				try
				{
					if (isolationLevel == IsolationLevel.Unspecified)
					{
						trans = session.Connection.BeginTransaction();
					}
					else
					{
						trans = session.Connection.BeginTransaction(isolationLevel);
					}
				}
				catch (HibernateException)
				{
					// Don't wrap HibernateExceptions
					throw;
				}
				catch (Exception e)
				{
					log.Error("Begin transaction failed", e);
					throw new TransactionException("Begin failed with SQL exception", e);
				}

				begun = true;
				committed = false;
				rolledBack = false;

				session.AfterTransactionBegin(this);
				foreach (var dependentSession in session.ConnectionManager.DependentSessions)
					dependentSession.AfterTransactionBegin(this);
			}
		}

38. Example

Project: LimeBean
Source File: DatabaseAccess.cs
View license
public void Transaction(Func<bool> action) {
            using(var tx = _connection.BeginTransaction(TransactionIsolation)) {
                var shouldRollback = false;

                _txStack.Push(tx);
                try {
                    shouldRollback = !action();
                } catch {
                    shouldRollback = true;
                    throw;
                } finally {
                    if(shouldRollback) {
                        _cache.Clear();
                        tx.Rollback();
                    } else {
                        tx.Commit();
                    }
                    _txStack.Pop();
                }
            }
        }

39. Example

Project: AntData.ORM
Source File: Database.cs
View license
public DataConnectionTransaction BeginTransaction(Statement statement)
        {
            // If transaction is open, we dispose it, it will rollback all changes.
            //
            if (Transactions != null)
                Transactions.Dispose();

            // Create new transaction object.
            DbConnection connection = null;
            try
            {
                connection = CreateConnection();
                connection.Open();
            }
            catch
            {
                if (connection != null)
                    connection.Close();
                throw;
            }

            if (statement.Hints != null && statement.Hints.Contains(DALExtStatementConstant.ISOLATION_LEVEL))
            {
                var level = (System.Data.IsolationLevel)statement.Hints[DALExtStatementConstant.ISOLATION_LEVEL];
                Transactions = connection.BeginTransaction(level);
            }
            else
            {
                Transactions = connection.BeginTransaction();
            }


            _closeTransaction = true;

            return new DataConnectionTransaction(new ConnectionWrapper(connection, this));
        }

40. Example

View license
internal static Task<int> ExecuteAsync(this IDatabaseConnectionDescriptor descriptor,
            string query)
        {
            return descriptor
                .GetTaskFactory(true)
                .StartNew(() =>
                {
                    using (descriptor.AcquireWriteLock())
                    {
                        try
                        {
                            using (var con = descriptor.GetConnection())
                            using (var tr = con.BeginTransaction(DefaultIsolationLevel))
                            {
                                var result = con.Execute(query, transaction: tr);
                                tr.Commit();
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw WrapException(ex, "ExecuteAsync", query);
                        }
                    }
                }, TaskCreationOptions.DenyChildAttach);
        }

41. Example

View license
internal static Task<int> ExecuteAsync(this IDatabaseConnectionDescriptor descriptor,
            string query, object param)
        {
            return descriptor
                .GetTaskFactory(true)
                .StartNew(() =>
                {
                    using (descriptor.AcquireWriteLock())
                    {
                        try
                        {
                            // System.Diagnostics.Debug.WriteLine("EXECUTE: " + query);
                            using (var con = descriptor.GetConnection())
                            using (var tr = con.BeginTransaction(DefaultIsolationLevel))
                            {
                                var result = con.Execute(query, param, tr);
                                tr.Commit();
                                return result;
                            }
                        }
                        catch (Exception ex)
                        {
                            throw WrapException(ex, "ExecuteAsyncWithParam", query);
                        }
                    }
                }, TaskCreationOptions.DenyChildAttach);
        }

42. Example

Project: CodeSnippets
Source File: Transactions.cs
View license
internal static void DbTransaction()
        {
            using (DbConnection connection = new SqlC/n ..... /n //View Source file for more details /n }

43. Example

View license
internal static Task ExecuteAllAsync(this IDatabaseConnectionDescriptor descriptor,
            IEnumerable<Tuple<string, object>> queryAndParams)
        {
            var qnp = queryAndParams.Memoize();
            return descriptor
                .GetTaskFactory(true)
                .StartNew(() =>
                {
                    using (descriptor.AcquireWriteLock())
                    {
                        try
                        {
                            using (var con = descriptor.GetConnection())
                            using (var tr = con.BeginTransaction(DefaultIsolationLevel))
                            {
                                foreach (var tuple in qnp)
                                {
                                    // tuple := (query, param)
                                    // System.Diagnostics.Debug.WriteLine("EXECUTE: " + qap.Item1);
                                    con.Execute(tuple.Item1, tuple.Item2, tr);
                                }
                                tr.Commit();
                            }
                        }
                        catch (Exception ex)
                        {
                            throw WrapException(ex, "ExecuteAllAsync",
                                qnp.Select(q => q.Item1).JoinString(Environment.NewLine));
                        }
                    }
                }, TaskCreationOptions.DenyChildAttach);
        }

44. Example

View license
public void ExecuteNonQuery(SqlNonQueryCommand command)
        {
            if (command == null) 
                throw new ArgumentNullException("command");

            using (var dbConnection = _dbProviderFactory.CreateConnection())
            {
                dbConnection.ConnectionString = _settings.ConnectionString;
                dbConnection.Open();
                try
                {
                    using (var dbTransaction = dbConnection.BeginTransaction(_isolationLevel))
                    {
                        using (var dbCommand = dbConnection.CreateCommand())
                        {
                            dbCommand.Connection = dbConnection;
                            dbCommand.Transaction = dbTransaction;
                            dbCommand.CommandTimeout = _commandTimeout;

                            dbCommand.CommandType = command.Type;
                            dbCommand.CommandText = command.Text;
                            dbCommand.Parameters.AddRange(command.Parameters);
                            dbCommand.ExecuteNonQuery();
                        }
                        dbTransaction.Commit();
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }

45. Example

View license
public async Task ExecuteNonQueryAsync(SqlNonQueryCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            using (var dbConnection = _dbProviderFactory.CreateConnection())
            {
                dbConnection.ConnectionString = _settings.ConnectionString;
                await dbConnection.OpenAsync(cancellationToken);
                try
                {
                    using (var dbTransaction = dbConnection.BeginTransaction(_isolationLevel))
                    {
                        using (var dbCommand = dbConnection.CreateCommand())
                        {
                            dbCommand.Connection = dbConnection;
                            dbCommand.Transaction = dbTransaction;
                            dbCommand.CommandTimeout = _commandTimeout;

                            dbCommand.CommandType = command.Type;
                            dbCommand.CommandText = command.Text;
                            dbCommand.Parameters.AddRange(command.Parameters);
                            await dbCommand.ExecuteNonQueryAsync(cancellationToken);
                        }
                        dbTransaction.Commit();
                    }
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }

46. Example

Project: CodeSnippets
Source File: Transactions.cs
View license
internal static void DbTransaction()
        {
            using (DbConnection connection = new SqlC/n ..... /n //View Source file for more details /n }

47. Example

Project: referencesource
Source File: DataContext.cs
View license
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Micr/n ..... /n //View Source file for more details /n }

48. Example

Project: BusinessPlatformApps
Source File: SqlUtility.cs
View license
public static DataTable RunCommand(string connectionString, string rawScript, SqlCommandType command/n ..... /n //View Source file for more details /n }

49. Example

View license
public int ExecuteNonQuery(IEnumerable<SqlNonQueryCommand> commands)
        {
            if /n ..... /n //View Source file for more details /n }

50. Example

View license
public async Task<int> ExecuteNonQueryAsync(IEnumerable<SqlNonQueryCommand> commands, Ca/n ..... /n //View Source file for more details /n }