This section describes how to deal with some frequently encountered problems faced by developers of applications that access a DB2 server. It addresses the following topics:
In addition, see "Developing Applications in DB2 Extended Enterprise Edition".
Important: This section represents a small sampling of the information available from DB2 Customer Service. For a complete and up-to-date source of DB2 information, use the DB2 Product and Service Technical Library at http://www.software.ibm.com/data/db2/library/.
When developing applications, ensure that:
A DB2 application should check the value of the SQL code or the SQL state element of the SQLCA data structure following each SQL statement. If it encounters a negative SQL code, it should take appropriate actions. For example, it should capture the SQL code and the SQLCA structure for later analysis.
For debugging purposes, the sqlaintp() API provides a formatted error message that you can display. For examples on how to use this API, refer to the Embedded SQL Programming Guide, and use the following sample programs: util.c for C, checkerr.cbl for COBOL, and util.f for FORTRAN.
Those negative SQL codes that result in a terminated connection are logged in the DB2 diagnostic log (db2diag.log). The database monitor application ID is also logged with the SQLCA on the server to enable you to identify the client and application.
If you are writing programs to handle data across various operating systems, you must consider the various code pages you will be using. See the Embedded SQL Programming Guide for details.
If the application is legacy code for a previous version of DB2, review the lists of incompatibilities in the Administration Guide.
When you experience problems at run time, ensure that:
After you start a query or application, you may suspect that it is either suspended (because it does not show any activity) or looping (because it shows activity, but no results are returned to the application). See "Responding to Suspensions and Loops" for information on how to restart your system in this situation.
After you restart your system, you may find the following tools helpful to diagnose problems with applications that cause loops or suspensions:
A function of the database system monitor is to display the status of all active agents. This information is useful when you are debugging. Ensure that statement collection is enabled before you run the application again, and preferably just after you run db2start. Use the following command:
db2 UPDATE MONITOR SWITCHES USING STATEMENT ON
For DB2 Extended Enterprise Edition, use:
;db2_all "db2 UPDATE MONITOR SWITCHES USING STATEMENT ON"
If you suspect that your application or query is either suspended or looping, try issuing the following command to capture snapshot information that may help you identify the source of the problem:
db2 GET SNAPSHOT FOR ALL APPLICATIONS ON database
For DB2 Extended Enterprise Edition use:
;db2_all "db2 GET SNAPSHOT FOR ALL APPLICATIONS ON database"
For information on db2_all, see "Commands for DB2 Extended Enterprise Edition".
This section covers some common troubleshooting tips related to CLI/ODBC applications.
When developing ODBC applications, note the following:
16-bit applications shipped before 1995 use an old set of 16-bit Driver Manager DLLs that do not function well in the 32-bit environment. For the old set of DLLs, problems include:
If (and only if) you are experiencing these problems, replace the 16-bit ODBC Driver Manager DLLs in the system subdirectory of the Windows operating system directory with the files in DB2's SQLLIB\MSODBC16 subdirectory.
You can configure the driver by using the DB2 Client Configuration Assistant:
(Alternatively, edit the db2cli.ini file and ensure that the keywords appear in the list of parameters listed after the alias of the database you are connecting to. If they are not there, edit the file and add them on separate line.)
Some ODBC applications (such as Lotus Approach) require unique indexes to be defined for any tables that are updated. For these applications, you must create a primary key or a unique index on any table that you are trying to update, or you will receive an error that you cannot perform the operation.
For information, see the DB2/Lotus Approach web page at http://www.software.ibm.com/data/db2/db2lotus. (Select the question, "Why does Approach open my DB2 table in read only mode?")