5. Working with a Database : How Programming for Multiple Sessions Works : How You Can Open a New Database Session : Examples of Opening New Database Connections
 
Share this page                  
Examples of Opening New Database Connections
The following examples show various ways to open a new database connection.
Using the OpenNewConnection method in the initialize block
The following initialize block locally declares the reference variable second_session for the DBSessionObject and uses the OpenNewConnection method to open a database session that is identical to the one for the calling frame:
initialize (
second_session = DBSessionObject;) =
begin
   second_session =
      CurFrame.DBSession.OpenNewConnection();
   ...
end;
Using the Connect method in the initialize block
The following initialize block uses the Connect method to open a connection to the videos database, specifying the user as marg and setting the arithmetic-handling mode of the session. The statement uses a globally-declared reference variable third_session for the DBSessionObject:
initialize (
status = integer;) =
begin
   status = third_session.Connect(database =
     'videos',
     flags = '-umarg -xw');
end;
Using the OpenNewConnection method in a frame-invoking statement
The following openframe statement in a calling frame establishes a new, identical database session for the called frame (newframe):
newframe = openframe newframe with dbsession =
   CurFrame.DBSession.OpenNewConnection();