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

Hello Peeps,
How Do i go about to establish a connection to Database with Sybase?
1 #!/nairvigv/bin/perl 2 use warnings; 3 use strict; 4 use DBI 5 my $dsn = "jdbc:sybase:Tds:sample.college.com:29813:"; 6 my $user="$ENV{'ESM_DBO'}"; 7 my $password="$ENV{'ESM_DBO_PASSWD'}"; 8 9 10 my $dbh = DBI -> connect($dsn,$user,$password)or die $DBI::errstr;

What am i doing wrong?
I get this  is not exported by the DBI module error

Replies are listed 'Best First'.
Re: PERL Sybase Connection
by haukex (Archbishop) on Feb 08, 2018 at 08:20 UTC
    I get this is not exported by the DBI module error

    You appear to be missing a semicolon on the use DBI line.

Re: PERL Sybase Connection
by kcott (Archbishop) on Feb 08, 2018 at 06:00 UTC

    G'day vighneshmufc,

    Have a look at DBI: connect, which has general examples of usage.

    Then look at DBD::Sybase which has a very large number of specific examples of usage. All examples show your "$dsn" starting with dbi:Sybase:.

    — Ken

Re: PERL Sybase Connection
by Corion (Patriarch) on Feb 08, 2018 at 08:30 UTC

    You are missing the semicolon at the end of the use DBI line.

    This lets Perl think that you wanted to pass some additional arguments to the use command, but then these arguments are empty, which confuses DBI as it seems to DBI that you are asking for an unnamed command for it to export. That error message is unfortunate but not easily fixable in a more general sense.

      I changed the format to CTlib
      my $esm_server = $ENV{'ESM_SERVER'}; die "ESM_SERVER is not set\n" u +nless defined $esm_server; 3 die "ESM_SERVER is empty\n" unless( length($esm_server) > 0 ); 4 print "server is $esm_server\n"; 5 my $esm_user = $ENV{'ESM_DBO'}; die "ESM_USER is not set\n" un +less defined $esm_user; 6 die "ESM_USER is empty\n" unless( length($esm_user) > 0 ); 7 print "user is$esm_user\n"; 8 my $esm_passwd = $ENV{'ESM_DBO_PASSWD'}; die "ESM_PASSWD is not + set\n" unless defined $esm_passwd; 9 die "ESM_PASSWD is empty\n" unless( length($esm_passwd) > 0 );; 10 11 12 use Sybase::CTlib; 13 require "$ENV{ESM_LIB_PERL}/sybCTlib.pl"; die "Not there" unless $ +ENV eq ""; 14 15 my $dbh = Sybase::CTlib ->new( $esm_user,$esm_passwd,$esm_server); ~
      Kinly guide me why do i get Can't locate Sybase/CTlib.pm
      The error msg is
      Can't locate Sybase/CTlib.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at databasee.txt line 18. BEGIN failed--compilation aborted at databasee.txt line 18.

        Seriously, why did you try to change to Sybase::CTlib if you don't have that module installed?

        The only thing you need to change in your original script is to add the missing semicolon, provided you have the Sybase DBD driver installed (DBD::Sybase).

        Kinly guide me why do i get Can't locate Sybase/CTlib.pm

        Perhaps because you have not installed Sybase::CTlib? Use diagnostics to help you understand error messages in future.

Re: PERL Sybase Connection
by karlgoethebier (Abbot) on Feb 08, 2018 at 10:21 UTC
    "...wrong?"

    Just some observations: this is your code without the line numbers and my shebang:

    #!/usr/bin/env perl use strict; use warnings; use DBI my $dsn = "jdbc:sybase:Tds:sample.college.com:29813:"; my $user = "$ENV{'ESM_DBO'}"; my $password = "$ENV{'ESM_DBO_PASSWD'}"; my $dbh = DBI->connect( $dsn, $user, $password ) or die $DBI::errstr; __END__

    This results in:

    karls-mac-mini:playground karl$ perl -c ./kaputt.pl "jdbc:sybase:Tds:sample.college.com:29813:" is not exported by the DBI + module Can't continue after import errors at ./kaputt.pl line 8. BEGIN failed--compilation aborted at ./kaputt.pl line 8.

    What perl sees is use DBI my $dsn = "jdbc:sybase:Tds:sample.college.com:29813:";

    But i guess you meant: use DBI; my $dsn = "jdbc:sybase:Tds:sample.college.com:29813:";

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help