Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: fail: Linux Perl-DBI to SQL Server

by pvaldes (Chaplain)
on May 15, 2013 at 22:26 UTC ( #1033746=note: print w/ replies, xml ) Need Help??


in reply to fail: Linux Perl-DBI to SQL Server

It seems that you have two problems here, the program can not find neither the database nor the driver...

1 - I could be wrong (I'm not familiar with the MicrosoftSQL DB) but I think that DBI use dbname=$mydatabase instead to database=$mydatabase, please check this.

2 - I find also strange the structure of the driver part. What is the purpose of the "{}"?. (UPDATED, you want to say: q{}?)

Check the name of your driver with something like:

perl -MDBI -e 'my @drivers = DBI->available_drivers; print join(", ", @drivers), "\n";'

(UPDATED: mmmh, the name is "Microsoft ODBC Driver 11 for SQL Server" or "ODBC Driver 11 for SQL Server"?)


Comment on Re: fail: Linux Perl-DBI to SQL Server
Download Code
Replies are listed 'Best First'.
Re^2: fail: Linux Perl-DBI to SQL Server
by madmole (Novice) on May 16, 2013 at 01:43 UTC

    Solved

    I have figured out what is going on and succeeded in connecting. The root of the problem is understanding the concept of a DSN. The basic syntax is:


    dbi:ODBC:dsn_name

    where dsn_name is a string that is used to index into a section header of one of the .ini files (e.g. odbcinst.ini).

    The problem is that there is an alternate syntax known as DSN-less connection strings (curly brackets) which essentially contains connection information inline. For some reason I never got this to work correctly, I believe because the DSN-less syntax never connected to the location of the driver .so file. When I refashioned my example to use DSN syntax the example succeeded. My updated code fragment looks like this:

    % cat simple.pl #!/usr/bin/perl use DBI; my $dsn="dbi:ODBC:DSN=tul1system"; my $dbh = DBI->connect($dsn, "user334", "2BEvPog"); if (! defined($dbh) ) { print "***Error connecting to DSN\n"; print "***Error was:\n"; print "***$DBI::errstr\n"; # $DBI::errstr is the error }

    Note that the other information like database name and IP address now come from the .ini file.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (14)
As of 2015-07-30 19:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls