beautypg.com

Chapter 4. deploying applications with db2, Figure 4-2 logic of sample application – IBM Data Server DB2 User Manual

Page 171

background image

Chapter 4. Deploying applications with DB2

157

Once the connection succeeds, the application outputs a message to the screen.
Then it releases the connection handle and environment handle in sequence.
Figure 4-2 shows the logic in our sample application.

Figure 4-2 logic of sample application

Note: A DSN-less connection means connecting to a data source without a
system level DSN or file DSN created. The connection string is used instead
of a system level DSN or file DSN to keep the data source connectivity
information. The CLI function SQLConnect() does not support a connection
string. That is why we use SQLDriverConnect() in our sample application.

An introduction to the three types of connection functions in CLI programming
can be found at the DB2 Information center:

http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.a
pdv.cli.doc/doc/t0004608.html

Allocate an environment Handle

SQLAllocHandle ()

Allocate an connection Handle

SQLAllocHandle ()

Make a connection to database

SQLDriverConnect ()

Obtain diagnostic information

SQLGetDiagRec ()

Disconnect from database

SQLDisconnect ()

Free the database handle

SQLFreeHandle ()

Free the environment handle

SQLFreeHandle ()

Application Start

Read connection info from cmd

Application End

Output error message

printf ()