Creating Connections

 

The first thing you have to do is to create object implementing the IDataSource interface - IRoot.CreateDataSource.

Second step is to set desired attributes influencing how the connection will be established. Almost all of these attributes are part of connection string - the IDataSource.ConenctionString property.

The final step is to realize the connection. If the AutoConnect property is true, the connection is realized immediately as the value of  ConnectionString property has been set. If connection string doesn't fully describe desired connection, a dialog arises giving a chance to user to complete connection. This can be suppressed by setting the value of AutoConnect to false. Then you have to assign the true value to the Connected property. This property also indicates active connection when it is true. The ConectionString property holds completed connection string after successful connection if AutoCommit is true.

You may also specify the access mode for the data source with taken of the OpenReadOnly property. If it is false then the data source will be opened in read/write mode, else in the read-only mode. The value can be changed only when there is no active connection, i.e. when the Connected property is false. This property always overrides the default setting of a data source.

If there is an active connection, it will be closed before new connection is done. But all statements created for previous connection will remain untouched, so they'll be unusable for next work => they have to be freed before any new connection is done.

 

The Connection String Syntax

connection-string ::= empty-string[;] | attribute[;] | attribute; connection-string
empty-string ::=
attribute ::= attribute-keyword=attribute-value | DRIVER=[{]attribute-value[}]
attribute-keyword ::= DSN | UID | PWD | driver-defined-attribute-keyword
attribute-value ::= character-string
driver-defined-attribute-keyword ::= identifier

DRIVER Description of a driver that represents desired database systems.
DSN Name of data source. For a file data source it must be FILEDSN. DSN and FILEDSN are mutually exclusive.
UID User's name
PWD User's password; A driver never supplies value of this attribute when completing the connection string.
SAVEFILE The file name of a .DSN file in which the attribute values of keywords used in the connection strings should be saved if the connection is success. It doesn't work with already created data sources. The .DSN extension is always added if the current one differs.

To see how the connection string looks in the real world, it's recommended to run ODBC Test demo and to see the returned connection string.

Some drivers, mainly MS Access ones, use attribute determining frequency of disk writes - PageTimeOut for MS Access. For example when specifying this attribute in connection string for MS Access database, a very high number of unneeded disk writes will occur.

The list of available drivers is accessible via the IDrivers interface.