Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Perl ODBC connection without password
- use DBI;
- my $strConn = "dbi:ODBC:MyDB";
- my $username = "username";
- my $password = "password";
- # Does work
- $dbh = DBI->connect( $strConn, $username, $password, { PrintError => 1, RaiseError => 1 } );
- # Does not work
- #$dbh = DBI->connect( $strConn, undef, undef, { PrintError => 1, RaiseError => 1 } );
- if ($dbh)
- {
- print "OKn";
- } else {
- print "FAILn";
- }
- use Win32::ODBC;
- my $dbh = new Win32::ODBC("odbc_connection_name");
- if ($dbh)
- {
- print "OKn";
- } else {
- print "FAILn";
- }
- use 5.010;
- use strict;
- use warnings;
- use Getopt::Long qw<GetOptions>;
- GetOptions( my %options, qw<user|u password|pwd|p> );
- # Non-option arguments will be left on @ARGV
- # this script also accepts script.pl [USER] [PASSWORD]
- usage( 'User not set!' ) unless ( $options{user} //= shift );
- usage( 'Password not set!' ) unless ( $options{password} //= shift );
- $dbh
- = DBI->connect(
- $strConn
- , @options{ qw<user password> }
- , { PrintError => 1, RaiseError => 1 }
- );
- $dbh
- = DBI->connect( join(
- ';'
- , 'DBI:ODBC:driver={SQL Server}'
- , "Server=$SQL_SERVER"
- , "Database=$SQL_DATABASE"
- , "UID=$option{user}"
- , "PWD=$option{password}"
- ));
Add Comment
Please, Sign In to add comment