Database Guide

Establishing database connections

The following examples show several methods for establishing a database connection.

"Connect to a database using a connection specification.
This example prompts you with a database logon window.
If you are already connected, this code just returns the
active connection."
| conSpec |
conSpec := AbtDatabaseConnectionSpec
     forDbmClass: #AbtIbmCliDatabaseManager
     databaseName: 'SAMPLE'.
     conSpec connect.
 
"Connect to a database and assign an alias to the connection"
| conSpec |
conSpec := AbtDatabaseConnectionSpec
     forDbmClass: #AbtIbmCliDatabaseManager
     databaseName: 'SAMPLE'.
     conSpec connectUsingAlias: 'SampleConSpec'.
 
"Connect to a database using a connection specification
and a logon specification.  This example does not prompt
you with a database logon window."
| conSpec logonSpec |
conSpec := AbtDatabaseConnectionSpec
     forDbmClass: #AbtIbmCliDatabaseManager
     databaseName: 'SAMPLE'.
logonSpec := AbtDatabaseLogonSpec
     id: 'userid'
     password: 'password'
     server: nil.
conSpec connectUsingAlias: 'SampleConSpec'
     logonSpec: logonSpec.
 
"Disconnect from a database using a connection specification.
Return the connection."
| conSpec activeConnection|
conSpec := AbtDatabaseConnectionSpec
     forDbmClass: #AbtIbmCliDatabaseManager
     databaseName: 'SAMPLE'.
     activeConnection := conSpec connect.
activeConnection disconnect;
     yourself.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]