next up previous contents index
Next: Accessing Tables in Data Up: Using the Interface Previous: Using the Interface   Contents   Index

Connecting to and Disconnecting from Data Sources

Assuming that the data source to be connected to is available, i.e. it has an entry in ODBC.INI file which can be checked by running Microsoft ODBC Administrator, it can be connected to in the following way:

| ?- odbc_open(data_source_name, username, passwd).

If the connection is successfully made, the predicate invocation will succeed. This step is necessary before anything can be done with the data sources since it gives XSB the opportunity to initialize system resources for the session.

This is an executable predicate, but you may want to put it as a query in a file that declares a database interface and will be loaded.

To close the current session use:

| ?- odbc_close.

and XSB will give all the resources it allocated for this session back to the system.

If you are connecting to only one data source at a time, the predicates above are sufficient. However, if you want to connect to multiple data sources at the same time, you must use extended versions of the predicates above. When connecting to multiple sources, you must give an atomic name to each source you want to connect to, and use that name whenever referring to that source. The names may be chosen arbitrarily but must be used consistently. The extended versions are:

| ?- odbc_open(data_source_name, username, passwd, connectionName).

and

| ?- odbc_close(connectionName).

A list of existing Data Source Names and descriptions can be obtained by backtracking through odbc_data_sources/2. For example:

| ?- odbc_data_sources(DSN,DSNDescr).
 
DSN = myoms
DSNDescr = MySQL driver;
 
DSN = mywinoms
DSNDescr = TDS driver (Sybase/MS SQL);


next up previous contents index
Next: Accessing Tables in Data Up: Using the Interface Previous: Using the Interface   Contents   Index
Luis Fernando P. de Castro 2003-06-27