ISecurityConnection.StartTransaction

Fore Syntax

StartTransaction(AutoCommit: Boolean): IConnectionTransaction;

Fore.NET Syntax

StartTransaction(AutoCommit: Boolean): Prognoz.Platform.Interop.Metabase.IConnectionTransaction;

Parameters

AutoCommit. Parameter in charge of the automatic saving of changed data on DB server.

Description

The StartTransaction method initiates a new transaction with DB.

Comments

If True is passed as a value of the AutoCommit parameter, and there is no visible calling of the Commit or the Rollback methods, when terminating the transaction the Commit method is called automatically to save all modified data. If the AutoCommit parameter has the False value, in case of similar conditions the Rollback method is called to rollback all changes.

Transaction termination is performed when the Dispose operator is explicitly used for the corresponding object in the code. Termination of incomplete transactions is also executed by a garbage collector when completing code execution.

Fore Example

Sub Main;
Var
   MB: IMetabase;
   DB: IDatabaseInstance;
   Connect: ISecurityConnection;
   Command: IDalCommand;
   Tran: IConnectionTransaction;
Begin
   MB := MetabaseClass.Active;
   DB := MB.ItemById("BD").Open(NullAs IDatabaseInstance;
   Connect := DB.Connection;
   Command := Connect.CreateCommand("Insert Into Table_1 values ('A',1)");
   Tran := Connect.StartTransaction(False);
Try
   Command.Execute;
   Tran.Commit;
Except
   Tran.Rollback;
End Try;
   Command.Close;
End Sub Main;

After executing the example connection to the DB server, on which the BD repository database is set, is performed. The SQL query, that inserts new records in the table with the Table_1 physical name, is created and executed for this connection. If there is any unsaved data, it is saved on the server.

Fore.NET Example

The requirements and result of the Fore.NET example execution match with those in the Fore example.

Imports Prognoz.Platform.Interop.Metabase;
Imports Prognoz.Platform.Interop.Dal;
Imports Prognoz.Platform.Interop.Db;

Public Shared Sub Main(Params: StartParams);
Var
   MB: IMetabase;
   DB: IDatabaseInstance;
   Connect: ISecurityConnection;
   Command: IDalCommand;
   Tran: IConnectionTransaction;
Begin
   MB := Params.Metabase;
   DB := MB.ItemById["BD"].Open(NullAs IDatabaseInstance;
   Connect := DB.Connection;
   Command := Connect.CreateCommand("Insert Into Table_1 values ('A',1)");
   Tran := Connect.StartTransaction(False);
Try
   Command.Execute();
   Tran.Commit();
Except
   Tran.Rollback();
End Try;
   Command.Close();
End Sub;

See also:

ISecurityConnection