Mono.Data.Sqlite.SqliteConnection.BeginTransaction C# (CSharp) Method

BeginTransaction() public method

Creates a new SqliteTransaction if one isn't already active on the connection.
Unspecified will use the default isolation level specified in the connection string. If no isolation level is specified in the connection string, Serializable is used. Serializable transactions are the default. In this mode, the engine gets an immediate lock on the database, and no other threads may begin a transaction. Other threads may read from the database, but not write. With a ReadCommitted isolation level, locks are deferred and elevated as needed. It is possible for multiple threads to start a transaction in ReadCommitted mode, but if a thread attempts to commit a transaction while another thread has a ReadCommitted lock, it may timeout or cause a deadlock on both threads until both threads' CommandTimeout's are reached.
public BeginTransaction ( IsolationLevel isolationLevel ) : SqliteTransaction
isolationLevel IsolationLevel Supported isolation levels are Serializable, ReadCommitted and Unspecified.
return SqliteTransaction
    public new SqliteTransaction BeginTransaction(IsolationLevel isolationLevel)
    {
      return (SqliteTransaction)BeginDbTransaction(isolationLevel);
    }

Same methods

SqliteConnection::BeginTransaction ( ) : SqliteTransaction
SqliteConnection::BeginTransaction ( IsolationLevel isolationLevel, bool deferredLock ) : SqliteTransaction
SqliteConnection::BeginTransaction ( bool deferredLock ) : SqliteTransaction

Usage Example

示例#1
0
        public void UpdateAllScores(List <Score> scores)
        {
            Mono.Data.Sqlite.SqliteConnection  conn  = null;
            Mono.Data.Sqlite.SqliteTransaction trans = null;
            try
            {
                conn  = openDbConnection();
                trans = conn.BeginTransaction();

                var command = conn.CreateCommand();
                command.Transaction = trans;
                command.CommandText = "DELETE FROM [Score]";
                command.ExecuteNonQuery();
                command.Dispose();

                foreach (var score in scores)
                {
                    this.addScore(conn, trans, score);
                }

                trans.Commit();
            }
            catch (Exception exc)
            {
                trans.Rollback();
                throw exc;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
All Usage Examples Of Mono.Data.Sqlite.SqliteConnection::BeginTransaction