Guest User

Untitled

a guest
Aug 25th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. Perl ODBC connection without password
  2. use DBI;
  3.  
  4. my $strConn = "dbi:ODBC:MyDB";
  5. my $username = "username";
  6. my $password = "password";
  7.  
  8. # Does work
  9. $dbh = DBI->connect( $strConn, $username, $password, { PrintError => 1, RaiseError => 1 } );
  10.  
  11. # Does not work
  12. #$dbh = DBI->connect( $strConn, undef, undef, { PrintError => 1, RaiseError => 1 } );
  13.  
  14. if ($dbh)
  15. {
  16. print "OKn";
  17. } else {
  18. print "FAILn";
  19. }
  20.  
  21. use Win32::ODBC;
  22.  
  23. my $dbh = new Win32::ODBC("odbc_connection_name");
  24.  
  25. if ($dbh)
  26. {
  27. print "OKn";
  28. } else {
  29. print "FAILn";
  30. }
  31.  
  32. use 5.010;
  33. use strict;
  34. use warnings;
  35. use Getopt::Long qw<GetOptions>;
  36.  
  37. GetOptions( my %options, qw<user|u password|pwd|p> );
  38. # Non-option arguments will be left on @ARGV
  39. # this script also accepts script.pl [USER] [PASSWORD]
  40. usage( 'User not set!' ) unless ( $options{user} //= shift );
  41. usage( 'Password not set!' ) unless ( $options{password} //= shift );
  42.  
  43. $dbh
  44. = DBI->connect(
  45. $strConn
  46. , @options{ qw<user password> }
  47. , { PrintError => 1, RaiseError => 1 }
  48. );
  49.  
  50. $dbh
  51. = DBI->connect( join(
  52. ';'
  53. , 'DBI:ODBC:driver={SQL Server}'
  54. , "Server=$SQL_SERVER"
  55. , "Database=$SQL_DATABASE"
  56. , "UID=$option{user}"
  57. , "PWD=$option{password}"
  58. ));
Add Comment
Please, Sign In to add comment