Allocate and initialize a SQL Server connection.
SqlOpen% ( loginrec%, server$ )
where
The identifier of a SQL Server connection. SqlOpen% returns 0 if a SQL Server connection cannot be created or initialized, or if your login to SQL Server fails. When 0 is returned, the DB-Library error handler is called to indicate the error.
Important Do not modify the identifier returned by SqlOpen% in any way. Modifying the SqlOpen% identifier can cause unpredictable results.
To communicate with SQL Server, DB-Library for Visual Basic requires a SQL Server connection. SqlOpen% allocates the data structure associated with the connection, sets up communication with the network, logs in to SQL Server, and initializes any default options. SqlOpen% returns an identifier that is subsequently used by almost every DB-Library for Visual Basic procedure. A program can open multiple connections with SQL Server. The same login record can be used for multiple calls to SqlOpen%.
SqlOpen% returns 0 when it encounters any of the errors in the following table:
Error | Description |
---|---|
SQLECONN | Server is unavailable or does not exist. |
SQLEPWD | Login is incorrect. |
SQLESQLPS | Maximum number of SQL Server connections already allocated. |
'Get a login record and set login attributes. Login% = SqlLogin%() Result% = SqlSetLUser%(Login%, "loginid") Result% = SqlSetLPwd%(Login%, "passwd") Result% = SqlSetLApp%(Login%, "myapp") 'Get a connection for communicating with SQL Server. Sqlconn% = SqlOpen%(Login%, "server")
SqlClose, SqlExit, SqlLogin%, SqlSetLoginTime%; Messages