Using Perl DBI to test ODBC Connections

If you have the DBI perl module, and the Win32 ODBC pm (optional), this little script can be used to check your connections and give a database DSN a quick test.


   #!perl -w   use DBI;   use Win32::ODBC;      print "ODBC Drivers \n";   my @drivers = DBI->available_drivers;   print join(", ", @drivers), "\n";      print "-------------------------------------------------------------------------\n";      my $d = join("", @drivers);   print "DBD::ODBC";   print "not" if ($d !~ /ODBC/);   print "installed\n";      print "-------------------------------------------------------------------------\n";      my @dsns = DBI->data_sources('ODBC');   foreach my $d (@dsns)   {   print "$d\n";   }      print "-------------------------------------------------------------------------\n";      my $dbh = DBI->connect('dbi:ODBC:DBASE02', 'browser', 'browser');   $dbh->disconnect() if ($dbh);      print "-------------------------------------------------------------------------\n";      my $dbh32 = DBI->connect('dbi:Win32-ODBC:DBASE02', 'browser', 'browser');   $dbh32->disconnect() if ($dbh32); 



Leave a Reply