Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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

Comment on sql connectivity
Select or Download Code
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-08-22 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (168 votes), past polls