Troubleshooting Guide
This chapter describes how to deal with some frequently encountered
problems faced by developers of applications that access a DB2 server.
These tips to prevent or overcome problems with applications were created from
information available from DB2 Customer Service. DB2 Customer Service
hears about customer problems and concerns, and so is ideally suited to
provide the tips found here. This chapter presents the following
topics:
In addition, see Developing Applications in DB2 Enterprise - Extended Edition.
Important: 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:
- [ ]
- Embedded SQL statements are syntactically and semantically correct.
If possible, try to step through SQL statements manually using the command
line processor before embedding them in an application. This method
ensures that you are using valid SQL statements that perform the required
function.
- [ ]
- You have the authorities and privileges needed to execute the SQL
statements.
- [ ]
- The application is not holding locks for excessive periods of time.
For more information, see Diagnosing locking problems.
- [ ]
- Your application is bound before you issue any static SQL
statements. For information on the sqlabndx bind API, refer
to the Administrative API Reference.
- [ ]
- You provide code to handle SQL errors in applications that connect to
DB2.
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 Application Development Guide, and use the following sample programs:
- util.c for C
- checkerr.cbl for COBOL
- util.f for FORTRAN
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.
- [ ]
- You provide enough memory for the variables you are using.
- [ ]
- You consider code page conversions.
If you are writing programs to handle data across various operating
systems, you must consider the various code pages you will be using.
Refer to the Application Development Guide for details.
- [ ]
- If your applications use user-defined functions, stored procedures,
distributed unit of work or multi-threading, you follow the guidelines in the
Application Development Guide and CLI Guide and Reference manuals.
- [ ]
- There are no incompatibilities with previous releases.
If the application is legacy code for a previous version of DB2, review the
lists of incompatibilities in the Administration Guide,
Design and Implementation.
At compile time, ensure that:
- [ ]
- Your compiler environment is correct and all include files and environment
variables are current. Refer to your compiler's documentation for
details.
- [ ]
- Your compiler options are correct. Refer to the Application Building Guide book for information specific to a supported compiler.
- [ ]
- No compiler error messages are received. (Correct any syntax errors
before proceeding.)
At link time, ensure that:
- [ ]
- The link options and link libraries are defined properly. For
information, refer to the Application Building Guide book for your platform.
When you experience problems at run time, ensure
that:
- [ ]
- You have EXECUTE privilege on packages that contain embedded SQL
statements, and the required authorities and privileges for all dynamic SQL
statements.
- [ ]
- You have looked for information about Java related applications, JDBC
(Java Database Connectivity) and SQLJ (Embedded SQL for Java), on the IBM DB2
and Java page at
http://www.software.ibm.com/data/db2/java.
- [ ]
- You have investigated any error messages you received. For example,
embedded SQL statements, DB2 API, or CLI statements may return error
messages.
- [ ]
- You step through embedded SQL statements manually from the command line
processor to find problems. This technique is recommended when
statements in an application run but produce the wrong results.
- [ ]
- You solve all application errors. A debugger may assist you.
- [ ]
- The application is not holding locks for excessive periods of time.
See Diagnosing locking problems, for more information.
- [ ]
- If you are using CLI/ODBC/JDBC applications, review the
considerations in the section Using CLI/ODBC/JDBC Applications.
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:
- The debugger you use with your compiler.
- The database system monitor. See Diagnosing locking problems and refer to the System Monitor Guide and
Reference for more information.
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 immediately after you run
db2start. Use the following command:
db2 UPDATE MONITOR SWITCHES USING STATEMENT ON
In a partitioned database environment use:
db2_all ";db2 UPDATE MONITOR SWITCHES USING STATEMENT ON"
The semi-colon(;) and db2_all combine to improve the
performance of the UPDATE command by issuing the command on all
partitions in the database.
If you suspect that your application or query is either suspended or
looping, issue the following command to capture snapshot information.
This may help you identify the source of the problem.
db2 GET SNAPSHOT FOR ALL APPLICATIONS ON database
In a partitioned database environment use:
db2_all ";db2 GET SNAPSHOT FOR ALL APPLICATIONS ON database"
For more information on db2_all, see Commands for DB2 Enterprise - Extended Edition.
This section covers some common troubleshooting tips related to
CLI/ODBC/JDBC applications.
When developing CLI/ODBC/JDBC applications, note the
following:
- [ ]
- You must use the PATCH1/PATCH2 keyword to specify a work-around for any
known problems with CLI/ODBC/JDBC applications. Set this
keyword by editing the db2cli.ini file or (for OS/2, Windows 95,
Windows 98, and Windows NT) by clicking the Service tab of the
CLI/ODBC Settings in the Client Configuration Assistant. See the Installation and Configuration Supplement guide for information on this keyword.
- Symptom
-
An application such as Microsoft Query, Microsoft Access or Lotus Approach
fails when connecting to a DB2 server. The SQL1003N message is
typically received or a General Protection Fault (GPF) occurs.
- Action
- Ensure that:
- [ ]
-
The DB2 CLI/ODBC driver is configured correctly.
You can configure the driver by using the DB2 Client Configuration
Assistant:
- Select the DB2 database alias you are configuring.
- Select the Properties push button. The Database
Properties window appears.
- Select the Settings push button. The CLI/ODBC Settings
window appears.
- Select the Advanced push button. A window appears where
you can set the configuration keywords. In particular, ensure
that:
- LONGDATACOMPAT=1 if you are accessing Large Object Binary (LOB)
data.
- UNDERSCORE=0 if there are underscore characters (_) in table names.
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.
- [ ]
- You have compatible Microsoft ODBC driver manager files. Updating
these files can solve GPFs.
- Symptom
- Table or field names in DB2 are in mixed case. They could created
in one type of application such as an ODBC application like Lotus Approach,
and then accessed using another method such as the DB2 Command Line
Processor. For example, the problem with accessing tables could be seen
when the following error message is returned from an SQL statement such
as: SELECT * FROM table1
SQL0204N "USERID.TABLE1" is an undefined name. SQLSTATE=42704
This error message is given even though the table exists, and is shown in
the Control Center list of tables or in a LIST TABLES command.
For example, the problem with accessing columns could be seen when the
following error message is returned from an SQL statement such as:
SELECT column1 FROM table2
SQL0206N "COLUMN1" is not a column in an inserted table, updated table, or any
table identified in a FROM clause or is not a valid transition variable for
the subject table of a trigger. SQLSTATE=42703
This error message is give even though:
- The column "column1" exists, and shows up in the Control Center
or
the SQL statement: SELECT tabname, colname FROM
SYSCAT.COLUMNS WHERE tabname='table2' returns the
appropriate information about the "column1" column.
- The SQL statement: SELECT * FROM table2 returns all the
columns, including the "column1" column.
This problem can also appear if the object is created with a name that uses
all uppercase characters, and the object name is specified using mixed case
and quotation marks. For instance, the statement: SELECT *
FROM "Org" would also return SQL0204N "USERID.Org" is an
undefined name. SQLSTATE=42704.
- Possible Cause
- The DB2 object name, including table and column names, is in mixed
case. The object name must be specified in the mixed case, enclosed in
double quotes, or DB2 will convert them to upper case.
This affects all SQL statements, including SELECT statements as well as
CREATE TABLE and DROP TABLE statements.
Many ODBC applications, including Lotus Approach, preserve the case of
table and column names. If you specify the table name and the column
name in mixed case when the table is created in the ODBC application then the
following SQL statement is sent to DB2:
CREATE TABLE "test1" ("col1" CHAR(5))
In this case DB2 preserves the lower case name because of the double
quotation marks around the table and column names. Any attempt to
access this table without enclosing the name with double quotation marks will
fail.
Objects in the Control Center with mixed case names are enclosed with
double quotation marks.
- Action
- If you are using an ODBC application to create DB2 tables then specify the
table and column names in upper case. They can then be accessed either
with or without the double quotation marks.
Enclose all object names in double quotes if you need to work with tables
and columns in mixed case.
For instance, if the following table is created, both SELECT statements
would succeed:
CREATE TABLE "User1"."Table1" ("column1" CHAR(5))
SELECT * FROM "User1"."Table1"
SELECT "column1" FROM "User1"."Table1"
- Symptom
- Several dialog boxes appear with error messages or warnings when running
ODBC (or CLI) applications such as Lotus Approach, Microsoft Access, or
Powerbuilder. The title of each dialog box indicates which function
returned the error or warning.
- Possible Cause
- These errors and warnings are a normal part of the communication that
occurs between DB2 and the applications. They do not necessarily
indicate a problem with DB2 or the application.
The errors and warnings are seen when the CLI/ODBC configuration
keyword POPUPMESSAGE is set to one in the db2cli.ini
file. This keyword is also accessible in the CLI/ODBC Settings
notebook which is available from the Client Configuration Assistant.
The parameter "Error popup" is located on the Service tab.
- Action
- The CLI/ODBC configuration keyword POPUPMESSAGE should be set to
zero for production systems.
For more information on the POPUPMESSAGE keyword, and the
db2cli.ini file, refer to "POPUPMESSAGE" in the "DB2
CLI/ODBC Configuration Keywords Listing" section of the CLI Guide and Reference manual.
To configure the DB2 CLI/ODBC driver using the DB2 Client
Configuration Assistant (if available on your operating system):
- Start the DB2 Client Configuration Assistant.
- Select the DB2 database alias you want to configure.
- Click on the Properties push button. The Database
Properties window opens.
- Click on the Settings push button. The CLI/ODBC
Settings window opens.
- Click on the Advanced push button.
- Click on the Service Tab and select the "Error popup"
parameter.
- Ensure that there is no check mark next to Popup error message
in the Value section.
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, refer to the Application Development
Guide and 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?"
To run Java stored procedures or user-defined functions
(UDFs) on an OS/2 server, you must install DB2 on an HPFS drive on the
server. This permits the stored procedure or UDF ".class" files
to be placed in the %DB2PATH%\function directory without truncating the
filename extension.
To build SQLJ programs, you must turn off the just-in-time compiler feature
of the Java Development Kit using the following command:
SET JAVA_COMPILER=NONE
Note: | SQLJ source files may include an end-of-file character (EOF) causing the SQLJ
translator 'sqlj' to fail with an exception similar to the
following:
|
Cursor.sqlj:122.2: Error: Java Parsing. Encountered: \u001a
Expected: > ; "abstract" ...; "public" ...; "interface" ...;
"#sql" ...; ";" ...;
Total 1 error.
To remove the offending EOF, open the SQLJ source file in a text editor
that does not automatically append an EOF, modify the file by adding a blank
line to the end of the file, and resave the file.
The DB2 ODBC Catalog Optimizer tool creates optimized catalog tables for
ODBC, CLI, and JDBC access.
The tool results in fewer locks on base system catalog tables for the
following reasons:
- Catalog query time is reduced.
- Amount of information returned by a call to an application is
reduced.
- Dealing with Performance Degradation
- Many applications written using ODBC or DB2 CLI interfaces make heavy use
of the system catalog. While this does not usually present a problem
for databases with a small number of database objects, it can lead to
performance problems when using these applications with larger DB2
databases. This performance degradation can be attributed to two main
factors:
- the amount of information that has to be returned to the calling
application
- the length of time that locks are held on the catalog tables
- Performance Enhancement with the db2ocat Tool
- The DB2 ODBC Catalog Optimizer Tool solves the problem of performance
degradation by creating alternative catalog tables that are optimized for ODBC
access by a particular application. This utility helps database
administrators to identify the subset of catalog information that is needed
for a particular application, and it creates an ODBC optimized catalog that
the application can use. As a result, few locks are placed on the base
system catalog tables, and catalog query times can be reduced substantially,
together with the amount of data returned as a result of such queries.
- Step 1: Create an ODBC optimized catalog(s) on the host
-
- To create an ODBC optimized catalog, db2ocat utility should be run by a
DBA on a Windows 95, Windows 98, or Windows NT workstation. db2ocat
provides a SmartGuide that takes the DBA through a process of naming the
catalog and specifying the tables and stored procedures that should be
available to a particular application. Once the tables and stored
procedures are identified, it creates ten new tables on the target database
server that comprise an ODBC optimized catalog of data objects available to
the application. These ten tables have a qualifier (creator) that is
the name of the ODBC optimized catalog.
- This step needs to be repeated for each application that would benefit
from an ODBC optimized catalog.
- Step 2: Configure each workstation to point to the right
ODBC-optimized catalog(s).
-
- Applications query the real DB2 system catalog to obtain metadata, by
default.
- IBM DB2 ODBC, CLI, and JDBC drivers provide a parameter that can be used
to point applications to different source of metadata that is optimized for
access by the ODBC, DB2 CLI, and JDBC applications.
- The parameter, CLISCHEMA, is set in the DB2CLI.INI file in the
subdirectory where DB2 products are installed (typically \sqllib). This
parameter applies only to the Data Source Name (DSN) for which it is
set.
- Any application that uses a DSN for which the CLISCHEMA parameter has been
set will obtain metadata from the ODBC-optimized catalog named by the
CLISCHEMA.
- The CLISCHEMA parameter can be set by manually editing the
DB2CLI.INI file or by using the db2ocat tool at each of the end-user
workstations. Because DB2CLI.INI is stored on each workstation,
administrators should consider strategies for distributing DB2CLI.INI
to end-users especially if the number of users is large.
- Step 3: Keep the ODBC optimized catalog(s) current.
-
- ODBC optimized catalogs, created with the db2ocat utility, produce a
separate copy of the data extracted form the DB2 system catalog
(SYSIBM). It is important to have a procedure that will propagate
future additions and changes in the system catalog to the ODBC optimized
catalogs.
- db2ocat provides a manual procedure, requiring that when catalog changes
occur, a Database Administrator start the db2ocat utility on a Windows 95,
Windows 98, or Windows NT workstation and press the Refresh button
for each ODBC optimized catalog that may be affected by the changes.
- Another option for keeping ODBC optimized catalogs current is available to
DB2 for OS/390 users that have IBM DataPropagator Relational Capture and Apply
products installed on their host system.
- This DataPropagator option allows Database Administrators to automatically
replicate all changes in the real system catalog to all ODBC optimized
catalogs.
Notes:
- DB2 Universal Database provides several CLI/ODBC initialization keywords
that can be used to limit the amount of data that is returned by the initial
PAI calls during the "information gathering" stage after the database is first
connected.
- CLISHEMA keywords in db2cli.ini file should be set to an ODBC
catalog schema. The CLISCHEMA option indicates an alternative schema,
tables, and index set to be searched instead of the SYSIBM (or SYSTEM, QSYS2)
schemas when the DB2 CLI and ODBC Catalog function calls are issued to obtain
catalog information.
- If you specify CLISCHEMA=`SERGE', the internal CLI/ODBC API calls
that normally reference system tables will reference the following user tables
instead:
- SERGE.TABLES
- SERGE.COLUMNS
- SERGE.SPECIALCOLUMNS
- SERGE.STATISTICS
A stored procedure is a type of application
stored on a database server. A calling procedure (or client
application) is run on the database client that calls the stored procedure
using an available API method.
The stored procedure, after being called or invoked by the client
application, runs on the database server and returns any results to the client
application.
The calling procedure and stored procedure can be written in any language
supported by DB2 on your operating system. They do not need to be
written in the same language.
To debug a stored procedure, run the stored procedure in debug mode.
Testing of the stored procedure can be done separate from the calling
application program. You can use the debugger supplied with your
language compiler to debug local FENCED stored procedures as you would with
other applications. Refer to the compiler documentation for information
on using the supplied debugger.
Refer to the Application Development Guide in the "Resolving Problems" section of the "Stored Procedures"
chapter for more information on troubleshooting stored procedures.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]
[ DB2 List of Books |
Search the DB2 Books ]