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!!

In reply to Battling Getopt::Long by Smaug

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.