Hello oh great Monks
I am trying to get information out of a MS-SQL 2000 DB. I was able to connect to the database until I changed my script to accept inputs for server, user and password.
I am obviously not using it correctly, but I have gotten hopelessly confussed reading the help and looking at SoPW.
I tried using Dumper to see what the hash holding the input had in and all it shows is:
$VAR1 = '1';<BR>
$VAR2 = undef;
I'm sure I messed up something. Any help would be great.
use strict;
use DBI;
use Data::Dumper;
use Getopt::Long qw (GetOptions);
my $help = "0";
my $server = "0";
my $user = "0";
my $password = "0";
#Set the options for GetOpt
Getopt::Long::Configure( "pass_through", "no_ignore_case", "prefix_pat
+tern=(-|\/)" );
#What to expect on the command line
my %opts = ();
my %opts=(GetOptions(
'help|?' => \$help,
'server' => \$server,
'user' => \$user,
'password' => \$password
));
print Dumper(%opts); #DEBUG: See what's there
if($opts{help}) {
&Help;
}
my $mytime=(time);
my $database="TNGDB";
#Start Logging to log file..
open (LOGF, ">>%0../../$mytime.log") || die "Could not open the Log Fi
+le: $!\n";
#Connect to MSSQL Server
my $dsn="driver={SQL Server};Server=$server;database=$database;UID=$us
+er;PWD=$password;";
my $dbh=DBI->connect("dbi:ODBC:$dsn", $user, $password) || die &Logger
+("...Unable to connect. Reason: $DBI::errstr");
&Logger ("...Success: connected to database $server\\$database\n");
#Get Data
#Insert the select statements here....
$sth->finish();
$dbh->disconnect();
########################################
## SUBS ##
########################################
# Message Logging
sub Logger {
my $text = shift;
my $rc = 0;
if (print LOGF "$text\n") {
$rc=1;
}
return ($rc);
}
#CLI Help
sub Help {
print "Invalid option.\n","The valid options are: \n";
print "MakeCVM.exe -h (or ? or help) displays this.\n";
print "MakeCVM.exe -server=<Server> -user=<SQL User> -password=<Pa
+ssword>";
}
The error I get running this is:
DBI connect('driver={SQL Server};Server=0;database=TNGDB;UID=0;PWD=0;'
+,'0',...)
failed: at E:\MakeCVM\makeCVM-SQL.pl line 41
1 at E:\MakeCVM\makeCVM-SQL.pl line 41.
Thank you in advance oh Great and wonderous Monks!!