Navigation:  Advantage .NET Data Provider > AdsTransaction Class >


Advantage .NET Data Provider

Previous pageReturn to chapter overviewNext page

Full name: Advantage.Data.Provider.AdsTransaction

Implements: System.Data.IDbTransaction



The AdsTransaction class represents a transaction running on Advantage Database Server. When the AdsConnection.BeginTransaction method is called, Advantage Database Server starts a transaction, and the BeginTransaction method returns an AdsTransaction object. To end the transaction, call either AdsTransaction.Commit or AdsTransaction.Rollback.

Advantage Local Server does not support transactions. You can use the BeginTransaction method and AdsTransaction objects when connected to Advantage Local Server, but the calls to AdsConnection.BeginTransaction, AdsTransaction.Commit, and AdsTransaction.Rollback are no-ops in that environment.

Unlike other .NET data providers, it is not necessary to assign the AdsTransaction object to the AdsCommand.Transaction property prior to using a command object in a transaction. With Advantage Database Server, all commands executed on an AdsConnection while that connection has a transaction active are automatically run in that transaction.


The following C# code connects to Advantage Database Server, makes an update in a transaction and then commits it if there are no errors.

public static void TestTransaction()


AdsConnection conn = new AdsConnection( "data source = c:\\data; " +

"ServerType=remote" );

AdsCommand cmd;

AdsTransaction txn;


// open the connection


// create a command object

cmd = conn.CreateCommand();

// specify an update

cmd.CommandText = "update departments set budget = budget * 1.05";

// start the transaction

txn = conn.BeginTransaction();




// execute the query

int iUpdates = cmd.ExecuteNonQuery();

// commit the transaction



catch( Exception e )


// some error occurred (e.g., a lock failure)

Console.WriteLine( e.Message );


// roll back the transaction





// close the connection.





See Also