Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Using DBI to make connection to a database by campbell

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found