Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^5: MSSQL/Perl

by mje (Curate)
on Sep 30, 2013 at 08:34 UTC ( #1056309=note: print w/replies, xml ) Need Help??

in reply to Re^4: MSSQL/Perl

UPDATE: appologies, I thought the post I was responding to was the first post and only just realised it was in the middle of the thread.

You've given us so little context so I'll have to assume you already know you want to use an ODBC.

DBI provides a single interface to multiple DBDs (DataBase Drivers). Most DBDs only support one database backend (e.g., DBD::Oracle only talks to Oracle, DBD::Pg only talks to postgres) and are usually built against a database supplied client library.

DBD::ODBC is an interface between DBI and the ODBC API so not just one database as many databases have ODBC Drivers. DBD::ODBC needs to link with an ODBC Driver Manager (unixODBC or the MS ODBC Driver Manager). When you use an ODBC Driver in perl:

  • your perl code tells DBI which perl DBD to load - the 'dbi:XXX' in the connect string. If you use 'dbi:ODBC', DBI loads the perl DBD::ODBC driver.
  • you pass a connection string through DBI which ends up in DBD::ODBC e.g., 'dbi:ODBC:DSN=mydsn'. DBD::ODBC passes this (DSN=mydsn) to the ODBC Driver manager (unixODBC) which uses 'DSN=mydsn' to work out which ODBC Driver to load.

So, to use DBD::ODBC you need to install a) unixODBC and b) an ODBC driver. The unixODBC packages you need are often called 'unixodbc' and unixodbc-dev. Then you'll need to get hold of the ODBC driver for your database, install that and tell unixODBC about it (usually by settings in an /etc/odbcinst.ini file.

Replies are listed 'Best First'.
Re^6: MSSQL/Perl
by tma2620 (Initiate) on Oct 02, 2013 at 15:25 UTC
    below is my code and the error, data retrieval part not included. I am on solaris 10 machine running perl 5.8.0. The default installation does not have DBD::ODBC so I downloaded and installed in my local library. I guess it is some kind of version conflict...pls help
    #!/opt/perl/5.8.0/bin/perl use lib "/home/myhome/lib"; use DBI; use DBD::ODBC; @ary = DBI->installed_drivers; print "@ary"; my ($data_source, $database, $userid, $password) = qw(;5000 db_1 read readP); my $connect_string = "driver={SQL Server};Server=$data_source;Database +=$database;UID=$userid;PWD=$password"; my $dbh = DBI ->connect ( "$connect_string" ) or die $DBI::errstr; my $sql = "select getdate()"; my $sth = $dbh->prepare ( $sql ); $sth->execute; $dbh->disconnect ();
    below is the error I get.
    DBI version 1.609 required--this is only version 1.35 at /opt/perl/5.8 +.0/lib/Exporter/ line 221. Compilation failed in require at line 4. BEGIN failed--compilation aborted at line 4.

      You should read about code tags when submitting a post here. The error "DBI version 1.609 required--this is only version 1.35" seems fairly straight forward to me. You are using a DBD::ODBC version that requires DBI 1.609 and you've only got DBI 1.35. Either upgrade DBI then rebuild DBD::ODBC or downgrade DBD::ODBC (the former is better in my opinion).

        my home library which I am using in the code has the latest DBI and DBD:ODBC. How can I override the old installation of DBI which is getting picked up from the common repository.  use lib "/home/myhome/lib";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056309]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2017-01-17 13:49 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (156 votes). Check out past polls.