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

Unsuccessfully I have been trying to connect to a remote Sybase database called ‘LNB_HHH_APP’ by using the Win32::ODBC module!

The ODBC administrator software on my local WinXP PC confirms that a valid user DSN name been created for the Sybase database, and drive listed of this database is the ‘DataDirect 4.0 Sybase Wire Protocol’. I have successfully tested the connection to the database by using the ‘Test Connect’ within the ODBC admin software after supplying the required login credentials.

I used the following bit of code to connect to the database – I have used the same code successfully in the past to connect to other MS Access database, so I thought that I could use it to connect to the Sybase instead! Maybe not.
use strict; use warnings 'all'; use Win32; use Win32::ODBC; my $dsn = "LNB_HHH_APP"; if (!(my $db = new Win32::ODBC($dsn))) { print "\nError connecting to $dsn\n\n"; print "\nError: " . Win32::ODBC::Error() . "\n"; exit; }
The errors I received were;
Error connecting to LNB_HHH_APP Error: [911] [] "[MERANT][ODBC Sybase Wire Protocol driver]Insufficien +t information to connect to the data source."
Can someone please shed some light on to this and why am I not able to connect successfully to the Sybase database? Is it to do with credentials? And How can I incorporate the user name and password to connect to the database within my script? Or do I need different Perl module for Sybase or another driver?

Thanks for the help

Replies are listed 'Best First'.
Re: Connecting to Sybase using Win32::ODBC
by inman (Curate) on Jun 09, 2004 at 10:50 UTC
    The connection strings required are usually specific to the database but typically a username and password to appear in there somewhere. You can also enable ODBC logging using the ODBC control panel applet. This may assist you.

    Not that it helps you with this but you might also want to look at the more traditional DBI/DBD modules. These work very well with ODBC sources and you are following a route where more monks will be able to assist you.

      I see.....

      OK, I tried this;
      use DBI; $dsn = 'LNB_HHH_APP'; $user = 'db_analyst'; $password = 'db_pass'; my $data_source = "dbi::Sybase:LNB_HHH_APP"; my $dbh = DBI->connect($data_source, $user, $password)||die "Can't con +nect to $data_source: $DBI::errstr";
      and got this in return
      Can't connect to data source LNB_HHH_APP, no database driver specified + and DBI_DSN env var not se t at U:\scripts\sybase_test1.pl line 6
      any thought? or an example code on how to connect to a sybase database and extract all rows from a query called 'LNB_Qry'?

      btw: swapping $data_source with $dsn still didnot resolve my problem.
        OK,....I changed the following;
        use DBI; $dsn = 'dbi:MDB:LNB_HHH_App'; $user = 'DB_analyst'; $password = 'DB_Pass'; $qry = 'dbo_vfunction_applications'; $dbh = DBI->connect($dsn,$user, $passwd); $ary_ref = $dbh->selectall_arrayref($qry);
        And this what I got back in return;
        DBD::DBM::db selectall_arrayref failed: Couldn't parse! <dbo_vfunction_applications>
        Any advice on how can I extract the data from the query $qry?

        Cheers

        Blackadder