use strict; use DBI; my $dbh =DBConnect(); my $sth = $dbh->prepare("SELECT * FROM WHATEVER"); ################ sub DBConnect{ # Connect to the database my $CONNECTIONSTRING = "DSN=mySystemDSN;" . "Uid=myUsername;" . "Pwd=myPassword" ; return DBI->connect("DBI:ODBC:$CONNECTIONSTRING", '','', # Username and password # Now set the DBI Attributes ... {RaiseError => 1, # do this, or check every call for errors ChopBlanks=> 1, LongTruncOk =>1, LongReadLen => 25} ) or die "Couldn't open database:'$CONNECTIONSTRING'\n $DBI::errstr; stopped"; }