http://qs321.pair.com?node_id=1132964

campbell has asked for the wisdom of the Perl Monks concerning the following question:

Greetings O enlightened ones

I have a problem with opening a handle to a database using the DBI Perl module, since, alas, I am a total DBI noob. I would figure it out myself, but I'm in a hurry...

I am using Strawberry Perl version 5.22 and Windows 7.

With the help of Windows' ODBC Data Source Administrator, I have configured a system DSN (named $myDSN), using the windows native ODBC driver (Version 06.01.7601) that connects to a MS-SQL database (named $db) on a remote server (named $srvr) on port $port with username $usr and password $pwd. I have tested the connectivity using the ODBC administrator, and it is fine.

The question is, how do I then get the DBI Perl module to use this information to set up a filehandle so that I can query / retrieve on the database?

I've tried to follow the syntax given in CPAN and (perhaps naively) tried the following:

my $dbh=DBI->connect("dbi:ODBC:Server=$srvr; UID=$usr;PWD=$pwd");
and
$DSN= 'dbi:DriverName:database=$db;host=$host;port=$port;' my $dbh=DBI->connect($DSN);

...which just results in various error messages to the effect that a connection isn't happening.

These error messages are, respectively:

DBI connect('variansystem; Server=10.1 75.68.28; UID='reports';PWD='reports'','',...) failed: [Microsoft][ODB +C Driver M anager] Data source name not found and no default driver specified (SQ +L-IM002) a t C:/Users/rpuser/Documents/RTDS/RTDS_include.pl line 232.
and
install_driver(DriverName) failed: Can 't locate DBD/DriverName.pm in @INC (you may need to install the DBD:: +DriverName module) (@INC contains: C:/Strawberry/perl/site/lib C:/Strawberry/per +l/vendor/l ib C:/Strawberry/perl/lib .) at (eval 16) line 3.

I'm obviously using the completely wrong syntax / approach (maybe I need to set enviroment variables or something?), but I haven't got the time to figure it out myself (which would obviously be more satisfying).

Thanks in advance.