dotConnect for SQLite Documentation
Devart.Data.SQLite Namespace / SQLiteTransaction Class
Members Example

In This Topic
    SQLiteTransaction Class
    In This Topic
    Represents a SQL transaction to be made in the SQLite database.
    Syntax
    'Declaration
     
    Public Class SQLiteTransaction 
       Inherits Devart.Common.DbTransactionBase
       Implements System.Data.IDbTransactionSystem.IDisposable 
    Remarks

    The application creates a SQLiteTransaction object by calling SQLiteConnection.BeginTransaction on the SQLiteConnection object. All subsequent operations associated with the transaction (for example, committing or aborting the transaction), are performed on the SQLiteTransaction object.

    The correlation between SQLiteConnection and SQLiteTransaction is always 1:1.

    Example
    The following example creates a SQLiteConnection and a SQLiteTransaction. It also demonstrates how to use the SQLiteConnection.BeginTransaction, Commit, and Rollback methods.
    public static void RunSQLiteTransaction(string myConnString) {
            using (SQLiteConnection sqConnection = new SQLiteConnection(myConnString)) {
                    sqConnection.Open();
                    // Start a local transaction
                    SQLiteTransaction myTrans = sqConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
                    SQLiteCommand sqCommand = sqConnection.CreateCommand();
                    try {
                            sqCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(52, 'DEVELOPMENT')";
                            sqCommand.ExecuteNonQuery();
                            sqCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(62, 'PRODUCTION')";
                            sqCommand.ExecuteNonQuery();
                            myTrans.Commit();
                            Console.WriteLine("Both records are written to database.");
                    }
                    catch (Exception e) {
                            myTrans.Rollback();
                            Console.WriteLine(e.ToString());
                            Console.WriteLine("Neither record was written to database.");
                    }
                    finally {
                            sqCommand.Dispose();
                            myTrans.Dispose();
                    }
        }
    }
    Public Shared Sub RunSQLiteTransaction(myConnString As String)
            Using sqConnection As New SQLiteConnection(myConnString)
                    sqConnection.Open()
                    ' Start a local transaction
                    Dim myTrans As SQLiteTransaction = sqConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted)
                    Dim sqCommand As SQLiteCommand = sqConnection.CreateCommand()
                    Try
                            sqCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(52, 'DEVELOPMENT')"
                            sqCommand.ExecuteNonQuery()
                            sqCommand.CommandText = "INSERT INTO Dept(DeptNo, DName) Values(62, 'PRODUCTION')"
                            sqCommand.ExecuteNonQuery()
                            myTrans.Commit()
                            Console.WriteLine("Both records are written to database.")
                    Catch e As Exception
                            myTrans.Rollback()
                            Console.WriteLine(e.ToString())
                            Console.WriteLine("Neither record was written to database.")
                    Finally
                            sqCommand.Dispose()
                            myTrans.Dispose()
                    End Try
        End Using
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.Data.Common.DbTransaction
             Devart.Common.DbTransactionBase
                Devart.Data.SQLite.SQLiteTransaction

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also