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

Re^4: MSSQL/Perl

by tma2620 (Initiate)
on Sep 30, 2013 at 00:39 UTC ( [id://1056264]=perlquestion: print w/replies, xml ) Need Help??

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

does DBI require unix-odbc drivers to be installed to work? I assumed the drivers come along with the DBI/DBD:ODBC etc..? I installed both DBI and DBD::ODBC but it says cant locate odbc.

Replies are listed 'Best First'.
Re^5: MSSQL/Perl
by mje (Curate) on Sep 30, 2013 at 08:34 UTC
    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.

      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( db_1:blah.pp.ns.net;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/Heavy.pm line 221. Compilation failed in require at mssql.pl line 4. BEGIN failed--compilation aborted at mssql.pl 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).

Re^5: MSSQL/Perl
by Anonymous Monk on Sep 30, 2013 at 02:11 UTC

    does DBI require unix-odbc drivers to be installed to work?

    No, DBI only requires DBD's -- data base drivers

    I assumed the drivers come along with the DBI/DBD:ODBC etc..?

    This usually isn't the case; DBD::SQLite is an exception

    I installed both DBI and DBD::ODBC but it says cant locate odbc.

    What is the exact error message (copy/paste)?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found