IBM DB2 manual Logic of sample application

Models: DB2

1 298
Download 298 pages 30.19 Kb
Page 171
Image 171

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

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-2shows the logic in our sample application.

Obtain diagnostic information

SQLGetDiagRec ()

Output error message

printf ()

Application Start

Read connection info from cmd

Allocate an environment Handle

SQLAllocHandle ()

Allocate an connection Handle

SQLAllocHandle ()

Make a connection to database

SQLDriverConnect ()

Disconnect from database

SQLDisconnect ()

Free the database handle

SQLFreeHandle ()

Free the environment handle

SQLFreeHandle ()

Application End

Figure 4-2 logic of sample application

Chapter 4. Deploying applications with DB2 157

Page 171
Image 171
IBM DB2 manual Logic of sample application