The GetConnect() function (Windows)
The GetConnect() function is available only in Windows™ environments and establishes a new explicit connection to a database server.
Syntax
void *GetConnect ( )
Usage
EXEC SQL connect to '@dbservername' with concurrent transaction;
- The ONEDB_SERVER environment variable in the Registry contains the name of the default database server. The Setnet32 utility sets the Registry values.
- The InfxServer field in the InetLogin structure can contain the name of the default database server or a specified database server. The client application sets the InetLogin fields.
For more information about the default and specified database server, see Sources of connection information in a Windows environment
void *cnctHndl;
;
strcpy(InetLogin.InfxServer, "mainsrvr");
;
cnctHndl = GetConnect();
EXEC SQL database stores7;
In the preceding example, if you had omitted the assignment to the InetLogin.InfxServer field, would establish an explicit connection to the stores7 database in the default database server (the database server that the ONEDB_SERVER environment variable in the Registry indicates).
EXEC SQL connect to 'stores7@mainsrvr' with concurrent transaction;
Situation | GetConnect() library function | SQL CONNECT statement |
---|---|---|
Connection name | Internally generated and stored in the connection handle structure for the connection | Internally generated unless CONNECT includes the AS clause; therefore, to switch to other connections, specify the AS clause when you create the connection. |
Opening a database | Only establishes an explicit connection to a database server; therefore, the application must use DATABASE (or some other valid SQL statement) to open the database. | Can establish an explicit connection to a database server and open a database when provided with names of both the database server and the database |
For each connection that you establish with GetConnect(), call ReleaseConnect() to close the connection and deallocate resources.
Return codes
- CnctHndl
- The call to GetConnect() was successful, and the function has returned a connection handle for the new connection.
- null pointer
- The call to GetConnect() was unsuccessful.