Skip to main content

Managing the Database Connection

Managing the Database Connection

To manage the database connection of an adapter, you can use the following properties and methods of the adapter.

Properties

The following properties control or provide information about the database connection:

Connected

%BooleanOpens in a new tab

This read-only property indicates if the adapter is currently connected.

ConnectAttrs

%StringOpens in a new tab

An optional set of SQL connection attribute options. For ODBC, they have the form:

attr:val,attr:val

For example, AutoCommit:1.

For JDBC, they have the form

attr=val;attr=val

For example, TransactionIsolationLevel=TRANSACTION_READ_COMMITTED.

Set this property in the OnInit() method of your business operation or business service to specify the options to use at connection time.

ConnectTimeout

%NumericOpens in a new tab

This property specifies the number of seconds to wait on each connection attempt. The default value is 5.

StayConnected

%NumericOpens in a new tab

This property specifies whether to stay connected to the remote system:

DSN

%StringOpens in a new tab

This data source name specifies the external data source to connect to. The following example shows the name of a DSN that refers to a Microsoft Access database:

accessplayground

Methods

Use the following methods to manage the database connection:

Connect()
Method Connect(pTimeout As %Numeric = 30) As %Status

Connects to the data source given by the current value of the DSN property.

Disconnect()
Method Disconnect() As %Status

Disconnects from the data source.

TestConnection()
Method TestConnection()

Tests the connection to the data source.

The adapter classes also provide several setter methods that you can use to set the properties listed in the preceding section.

FeedbackOpens in a new tab