DBI->connect
call?From DBD::ODBC 0.21, you can put all of the connection attributes specified in your odbc.ini
file in the connection string passed to DBI->connect()
.
For example, suppose your odbc.ini
file looked like this:
[dsn_name] ServerPort = demo.easysoft.com:8888; LogonUser = fred LogonAuth = password TargetDSN = remotedsn
You can remove the need for the odbc.ini
file and use the following Perl instead:
my $DSN = 'DRIVER={ODBC-ODBC Bridge};ServerPort=demo.easysoft.com:8888;'; $DSN = $DSN . 'LogonUser=fred;LogonAuth=password;TargetDSN=remotedsn'; my $dbh = DBI->connect("dbi:ODBC:$DSN", "database_user", "database_password") || die "Database connection failed: $DBI::errstr";
This can be particularly useful if you want to hide your username and password. For example, you don't want authentication details stored in plain text in the odbc.ini
file. Your Perl program could also retrieve the username and password from another file or even prompt for them.