Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

sql connectivity

by mrscr
on Jan 05, 2007 at 11:11 UTC ( #593094=perlquestion: print w/replies, xml ) Need Help??
mrscr has asked for the wisdom of the Perl Monks concerning the following question:

HI all,

I want to connect sql server on my machine to application which is on another machine and i am doing this by ODBC calls .I made one file dsn and used the perl syntax as

 my $connection = new Win32::ODBC($DSN);where $DSN="C:/Program Files/Common Files/ODBC/Data Sources/Test.dsn";

the error i got is :

Error connecting to SQLServer Use of uninitialized value in concatenation (.) or string at C:/Perl/s +ite/lib/Wi n32/ODBC.pm line 785. Error : [911] [] "[Microsoft][ODBC Driver Manager] Data source name no +t found an d no default driver specified"/

please help me to get out of this

Replies are listed 'Best First'.
Re: sql connectivity
by EdwardG (Vicar) on Jan 05, 2007 at 12:32 UTC

    $DSN probably needs to be a connection string rather than a filename.

    For example,

    $DSN="Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"

    See also http://www.connectionstrings.com

    See also perldoc Win32::ODBC

    NAME Win32::ODBC - ODBC Extension for Win32 SYNOPSIS To use this module, include the following statement at the top of +your script: use Win32::ODBC; Next, create a data connection to your DSN: $Data = new Win32::ODBC("MyDSN"); NOTE: *MyDSN* can be either the *DSN* as defined in the ODBC Administrator, *or* it can be an honest-to-God *DSN Connect String +*. Example: "DSN=My Database;UID=Brown Cow;PWD=Moo;"

     

Re: sql connectivity
by jbert (Priest) on Jan 05, 2007 at 12:39 UTC
    I think this is the relevant error message: "Data source name not found and no default driver specified".

    You've passed a filename as the DSN, but the docs say: "NOTE: MyDSN can be either the DSN as defined in the ODBC Administrator, or it can be an honest-to-God DSN Connect String."

    If you look in your ODBC administrator for the name of your DSN (not the filename) you might have more luck.

    You might want to give a little thought as to whether using Win32::ODBC is the way to go. I think most perl code uses DBI (or a layer over the top of DBI) as the database interface and there is a DBD::ODBC module to provide an ODBC back-end to DBI. There might be some ODBC-specific API calls in Win32::ODBC you need, though.

    Using DBI might allow your code to be more portable (to other DBs or platforms) in the future.

      And DBI has a driver to access ODBC - DBD::ODBC

      just another cpan module author

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://593094]
Approved by Corion
help
Chatterbox?
[perldigious]: So I don't envy you mountain guys if you have to drive in the winter, even with tire chains.
MidLifeXis waves.
[stevieb]: man, I absolutely LOVE driving in the worst winter conditions. In the mountainous roads, there are extremely few (if any) other drivers. I love the challenge. I've been doing extreme off-road my whole life, and as I said, I'm always well...
[stevieb]: ...prepared for even the very worst
Discipulus seems a part of the globe very unfrindly with Kawasaki riders..
[thezip]: My doggies love it when it snows
[perldigious]: As long as you are a good "boy scout" stevieb, more power to you... but I like my Jeep, and don't like the idea of rolling it or crashing it in to anything. :-)
[thezip]: Me, not as much.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2016-12-06 16:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.