BeginTransaction Method (IsolationLevel)
Collapse the table of content
Expand the table of content

SqlCeConnection.BeginTransaction Method (IsolationLevel)

Begins a database transaction with the current IsolationLevel value.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in

public SqlCeTransaction BeginTransaction (
	IsolationLevel isolationLevel
public SqlCeTransaction BeginTransaction (
	IsolationLevel isolationLevel
public function BeginTransaction (
	isolationLevel : IsolationLevel
) : SqlCeTransaction
Not applicable.



The transaction isolation level for this connection.

Return Value

An object representing the new transaction.

You must explicitly commit or roll back the transaction using the Commit or Rollback method.

The following example creates a SqlCeConnection and a SqlCeTransaction, and then demonstrates how to use the BeginTransaction, Commit, and Rollback methods.

SqlCeConnection conn = new SqlCeConnection("Data Source = AdventureWorks.sdf;");

// Start a local transaction; SQL Mobile supports the following 
// isolation levels: ReadCommitted, RepeatableRead, Serializable
SqlCeTransaction tx = conn.BeginTransaction(IsolationLevel.ReadCommitted);

// By default, commands run in auto-commit mode; 
SqlCeCommand cmd1 = conn.CreateCommand();

// You may create multiple commands on the same connection
SqlCeCommand cmd2 = conn.CreateCommand();

// To enlist a command in a transaction, set the Transaction property
cmd1.Transaction = tx;

    cmd1.CommandText = "INSERT INTO FactSalesQuota " +
        "(EmployeeKey, TimeKey, SalesAmountQuota) " +
        "VALUES (2, 1158, 150000.00)";


    // Auto-commited because cmd2 is not enlisted in a transaction
    cmd2.CommandText = "INSERT INTO FactSalesQuota " +
        "(EmployeeKey, TimeKey, SalesAmountQuota) " +
        "VALUES (3, 1157, 15000.00)";


    // Commit the changes to disk if everything above succeeded;
    // Use Deferred mode for optimal performance; the changes will 
    // be flashed to disk within the timespan specified in the 
    // ConnectionString 'FLUSH INTERVAL' property; 

    // Alternatively, you could use:
    // tx.Commit(CommitMode.Immediate);
    // or use default (Deferred) commit mode:
    // tx.Commit()
catch (Exception)
    // Handle errors here

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

© 2015 Microsoft