Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Help needed for Win32::ODBC

by YAFZ (Pilgrim)
on Oct 22, 2004 at 12:50 UTC ( [id://401464]=perlquestion: print w/replies, xml ) Need Help??

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

Dear monks,

I'm trying to connect to a remote MS SQL Server from within a Perl script running on my Win2K PC (ActiveState, perl, v5.8.0 built for MSWin32-x86-multi-thread). I've set up both user and system DSN (Data Source Name) pointing to that server. I also checked the connection, and in addition I fired up MS Access and was able to see the remote DB using that DSN. However I cannot make Perl connect to DB.

Here is my primitive code:
#! /usr/bin/perl use strict; use warnings; use Win32::ODBC; my $db; my $DSN = "DSN:IBUeMBA_DSN;UID=sa;PWD=xxxx"; if (!($db = new Win32::ODBC($DSN))) { print "Error connecting to $DSN\n"; print "Error: " . Win32::ODBC::Error() . "\n"; exit; }
When I run the programme above I receive the following error:
Error connecting to DSN:IBUeMBA_DSN;UID=sa;PWD=xxxx Error: [911] "[Microsoft][ODBC Driver Manager] Data source name not f +ound and no default driver specified"

I cannot understand why it doesn't find the DSN. Any ideas? I'm simply stuck at this point.

Replies are listed 'Best First'.
Re: Help needed for Win32::ODBC
by olivierp (Hermit) on Oct 22, 2004 at 13:22 UTC
    $DSN is incorrect.
    Try with my $DSN = "DSN=IBUeMBA_DSN;UID=sa;PWD=xxxx;";
    This outside link can also help you out when dealing with "DSN"s in general.

    --
    Olivier
      Oh my! I simply missed that, thanks a lot for figuring out :)
        You may want to do a DSN less connection instead of relying on a preconfigured DSN. This allows you to move and run this script to any machine with the DB Client.
        use warnings; use strict; use Win32::ODBC; my $DSN = "driver={SQL Server};server=myservername;database=mydb;uid=s +a;pwd=xxxx"; if (!(my $input = new Win32::ODBC($DSN))){ print "Failure opening connection. \n\n"; exit(); }else{ print "Success (connection #", $input->Connection(), ")\n\n"; }
Re:Help needed for Win32::ODBC
by Anonymous Monk on Oct 22, 2004 at 14:19 UTC

    Below the textarea:

    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 editor intervention).

    Please edit your post so it follows this rule...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://401464]
Approved by cbraga
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-16 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found