Easysoft ODBC-ODBC Bridge

Do I have to set the DBI_DSN, DBI_USER and DBI_PASS environment variables before running my Perl script?

Last Reviewed:
9th January 2024

Not unless your Perl script uses these environment variables.

The DBD::ODBC installation and test procedure requires these environment variables to be set, because it calls DBI->connect without any arguments. From the DBI documentation:

$dbh = DBI->connect($data_source, $username, $password, \%attr)

The $data_source value should begin with dbi:driver_name:. The driver_name specifies the driver that will be used to make the connection. (Case is significant.)

As a convenience, if the $data_source parameter is undefined or empty, the DBI module will substitute the value of the environment variable DBI_DSN. If just the driver_name part is empty (i.e., the $data_source prefix is dbi::), the environment variable DBI_DRIVER is used. If neither variable is set, connect dies.

If $username or $password are undefined (rather than just empty), the DBI module will substitute the values of the DBI_USER and DBI_PASS environment variables, respectively. The DBI will warn if the environment variables are not defined.

The documentation also suggests that using these environment variables is not recommended for security reasons and that this mechanism is intended to simplify testing. To avoid using the DBI_xyz environment variables, specify the values directly in the call to DBI->Connect:

DBI->Connect('dbi:ODBC:dsn_name', 'username', 'password')

Obviously, you can prompt for the username/password instead.

Applies To

Knowledge Base Feedback

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

(* Required Fields)