Opening a Connection

The SqlOpen% function logs in to SQL Server (using the SqlLogin% login record) and establishes a connection. The parameters required by the SqlOpen% function are the SqlLogin% login record identifier and a SQL Server server name. For each connection it establishes, SqlOpen% returns a connection identifier.

The SqlOpen% connection identifier remains associated with the connection as long as the connection is active. This documentation uses the variable sqlconn% to represent the connection identifier returned by SqlOpen%. Because most DB-Library for Visual Basic functions perform operations that are associated with a particular connection, most functions require you to specify the sqlconn% connection identifier as the first parameter.

Important Do not modify a connection's identifier in any way. If you modify an identifier, the connection and its associated data can be lost.

Once you open a connection with the SqlOpen% function, a data structure is associated with that connection to store a variety of information about the connection and its interaction with SQL Server. Your application uses DB-Library for Visual Basic functions to extract this information.

The following program fragment uses SqlOpen% to open a single SQL Server connection:

'Get a connection for communicating with SQL Server.
Sqlconn% = SqlOpen%(Login%, "server")

You can use SqlOpen% to open two or more SQL Server connections at the same time.