GET CONNECTION

Embedded SQL for C and SQL Server

Embedded SQL for C and SQL Server

GET CONNECTION

The GET CONNECTION statement retrieves the DBPROCESS pointer for the specified connection and stores the pointer in a host variable for use with DB-Library function calls.

Syntax

GET CONNECTION connection_name INTO :hvar

Arguments

connection_name

Is a previously opened connection.

hvar

Is the host variable, declared as data type DBPROCESS *. The hvar option is used to store the DB-Library connection pointer. The pointer can then be used with DB-Library function calls.

Remarks

The GET CONNECTION statement stores the DB-Library DBPROCESS pointer for an ESQL/C connection in a host variable. This is useful if you want to use features or functions that are specific to DB-Library (such as text and image handling functions) in your ESQL/C program.

As with all DB-Library programs, you must first use #define to define the appropriate platform before you include the DB-Library header files Sqlfront.h and Sqldb.h and link to the appropriate DB-Library .lib file.

  • Programs for Microsoft® Windows NT® 4.0, Microsoft Windows® 95, and Microsoft Windows 98 must first use #define DBNTWIN32 and then link to Ntwdblib.lib.

  • Programs for 16-bit Windows and QuickWin must first use #define DBMSWIN and then link to Msdblib3.lib.

  • Programs for Microsoft MS-DOS® must first use #define DBMSDOS and then link to Msdblib3.lib.

If you are using a WHENEVER statement in your program, the Embedded SQL keyword sqlerror must not be uppercase to avoid conflict with the DB Library-defined constant SQLERROR.

Examples
#define DBNTWIN32
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>

   .
   .
   .

EXEC SQL BEGIN DECLARE SECTION;
DBPROCESS* dbproc;
EXEC SQL END DECLARE SECTION;

EXEC SQL CONNECT TO gizmo.pubs
   AS my_connection
   USER sa
EXEC SQL GET CONNECTION my_connection
   INTO dbproc;
if (dbproc != NULL)
{
   printf("Got DBPROCESS connection, current database is '%Fs'\n",
      dbname(dbproc));
}
else
{
   printf("ERROR: Getting DBPROCESS connection\n");
}

See Also

CONNECT TO