SQLOpen (function)

Syntax

SQLOpen(login$ [,[completed$] [,prompt]])

Description

Establishes a connection to the specified data source, returning a Long representing the unique connection ID.

Comments

This function connects to a data source using a login string (login$) and optionally sets the completed login string (completed$) that was used by the driver. The following table describes the parameters to the SQLOpen function:

 

Parameter

Description

 

login$

String expression containing information required by the driver to connect to the requested data source. The syntax must strictly follow the driver's SQL syntax.

 

completed$

Optional String variable that will receive a completed connection string returned by the driver. If this parameter is missing, then no connection string will be returned.

 

prompt

Integer expression specifying any of the following values:

 

 

Value

Meaning

 

 

1

The driver's login dialog box is always displayed.

 

 

2

The driver's dialog box is only displayed if the connection string does not contain enough information to make the connection. This is the default behavior.

 

 

3

The driver's dialog box is only displayed if the connection string does not contain enough information to make the connection. Dialog box options that were passed as valid parameters are dimmed and unavailable.

 

 

4

The driver's login dialog box is never displayed.

 

The SQLOpen function will never return an invalid connection ID. The following example establishes a connection using the driver's login dialog box:

  id& = SQLOpen("",,1)

The Basic Control Engine returns 0 and generates a trappable runtime error if SQLOpen fails. Additional error information can then be retrieved using the SQLError function.

Before you can use any SQL statements, you must set up a data source and relate an existing database to it. This is accomplished using the odbcadm.exe program.

Example

This example connects the data source called "sample," returning the completed connection string, and then displays it.

Sub Main()
  Dim s As String
  id& = SQLOpen("dsn=SAMPLE",s$,3)
  MsgBox "The completed connection string is: " & s$
  id& = SQLClose(id&)
End Sub

See Also

SQLClose (function)

 

 

 

 

More information

S