SQLOpen

Syntax

SQLOpen(Connect$, Output$, DriverPrompt)

Remarks

Establishes a connection with a data source. A connection established with SQLOpen can be used throughout a macro until the connection is closed with SQLClose. Note that SQLOpen can prompt the user for additionally needed connection information.

Argument

Explanation

Connect$

The information necessary to establish a connection to a data source. Note that any data-source name that is used in Connect$ must be an existing data-source name defined with ODBC Setup or the ODBC Administration Utility. For more information on how to define data-source names, see "Setting Up Data Sources" earlier in this appendix.

Note that Connect$ should follow the format described in the Help file for the appropriate ODBC driver. This string may require the data-source name, one or more user IDs, one or more passwords, and any other information necessary to successfully connect to the particular DBMS.

Output$

A predefined string variable where you want the completed connection string to be placed. If Output$ is omitted, a completed connection string will not be returned.


Argument

Explanation

DriverPrompt

A number from 1 to 4 specifying if, and how, the driver should display prompts. This sets the fDriverCompletion flag in the ODBC API SQLDriverConnect function.

1 Always display a dialog box. The flag is set to SQL_DRIVER_PROMPT.

2 Display a dialog box only if there is not enough information to connect. The driver uses information from the connection string and from the data source specification as its defaults. The flag is set to SQL_DRIVER_COMPLETE.

3 Same as 2, but the driver grays and disables any unnecessary prompts. The flag is set to SQL_DRIVER_COMPLETE_REQUIRED.

4 If the connection string is unsuccessful, do not display a dialog box. The flag is set to SQL_DRIVER_NOPROMPT.


If the connection is successfully established, SQLOpen returns a connection
ID number. Use the connection ID number with other functions to reference that connection.

If SQLOpen is unable to connect with the information provided, it returns the error value 0 (zero). In such cases, and if more information is available, SQLOpen places error information in memory for the error functions to return,
if such information is available.

Examples

This example uses SQLOpen to create a connection to a Microsoft Access data source without displaying unnecessary prompts.


connect_num = SQLOpen("mydata.mdb", output_string$, 2)

The following example uses SQLOpen with a complex Connect$.


connect_num = SQLOpen("DSN = MyServer; UID = dbayer; PWD = 123; \
    Database = pubs", output_string$, 1)