Managing SQLFire Transactions

SQLFClientConnection implements methods to help you delimit SQLFire transactions in your application code. You begin and commit transactions using the connection object itself.

The following example uses an SQLFDataAdapter object to insert and update table data within as a single transaction.
string sqlfHost = "localhost";
int sqlfPort = 1527;
string connectionStr = string.Format(@"server={0}:{1}", sqlfHost, sqlfPort);

SQLFClientConnection connection = null;

try
{
    // Open connection, disable auto-commit, and start transaction
    connection = new SQLFClientConnection(connectionStr);
    connection.AutoCommit = false;
    connection.BeginSQLFTransaction(IsolationLevel.ReadCommitted);

    SQLFCommand command = connection.CreateCommand();
    command.CommandType = CommandType.Text;

    connection.Open();

    // Get product info
    command.CommandText = "SELECT * FROM product WHERE product_id=?";
    SQLFDataAdapter adapter = command.CreateDataAdapter();
    DataTable table = new DataTable("product");
    adapter.Fill(table);

    // Create new order
    command.CommandText = "INSERT INTO orders VALUES(?, ?, ?, ?, ?)";                
    command.ExecuteNonQuery();

    // Create new order detail
    command.CommandText = "INSERT INTO orderdetail VALUES(?, ?, ?, ?, ?)";
    command.ExecuteNonQuery();

    // Update product quantity
    command.CommandText = "UPDATE product SET quantity=? WHERE product_id=?";
    command.ExecuteNonQuery();

    // Commit transaction
    connection.Commit();
}
catch (Exception e)
{
    ///
    /// Log or re-throw exception
    /// 
}
finally
{
    connection.Close();
}