How can I debug my Perl DBI, DBD::ODBC?

Article:
00089
Last Reviewed:
8th January 2024
Revision:
1

Print out the contents of $DBI::errstr when an error occurs. This often shows more detail, e.g. If the ODBC driver posts multiple errors, all of them can be seen.

You can enable Perl DBI tracing for all handles using the DBI class method with:

DBI->trace($trace_level)
DBI->trace($trace_level, $trace_filename)

To enable trace information for a specific handle use $h->trace.

Trace level is a number between 0 and 9 but usually 2 is sufficient.

More detailed information is included in the Perl documentation. Try typing perldoc DBI. You might also like to look up the DBI_TRACE environment variable in the Perl DBI documentation.

Recent versions of DBI include DBI::Shell which allows you to use DBI to examine your database from a shell session. This can be a useful way of verifying that your driver is installed and working. Start dbish with either:

perl -MDBI::Shell -e shell

or

dbish

You will be provided with a choice of drivers and then once a driver is chosen, a choice of data sources. e.g.:

$ dbish
DBI::Shell 10.6 using DBI 1.13

WARNING: The DBI::Shell interface and functionality are
=======  very likely to change in subsequent versions!

Available DBI drivers:
 1: dbi:ADO
 2: dbi:ExampleP
 3: dbi:ODBC
 4: dbi:Proxy
Enter driver name or number, or full 'dbi:...:...' DSN: 3

Enter data source to connect to:
 1: DBI:ODBC:Postgres
 2: DBI:ODBC:test
Enter data source or number, or full 'dbi:...:...' DSN: 2
Connecting to 'DBI:ODBC:test' as ''...
@DBI:ODBC:test>

You can now enter dbish commands and SQL to query/change your database. A good start is usually "/table_info", which lists all your tables. See perldoc DBI::Shell for a list of commands.

See Also
Applies To

Knowledge Base Feedback

* Did this content help you?
* Please select one option based on your first choice:

(* Required Fields)