Connecting Sybase ASE tp Perl

Posted on 2003-03-16
Medium Priority
Last Modified: 2010-08-05

I need to connect Ase to Perl. I have no Idea about using perl.  am quite comfortable with ASE. Can someone help me out.

Question by:CYRI
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

gpadhy earned 260 total points
ID: 8151656
use DBI;
use strict;
my($database) = "SYBTST01";
my($data_source) = "DBI:Sybase:$database";
my($username) = "sa";
my($passwd) = "";
my($sel_statement) = "SELECT uid, name, type FROM sysobjects";
my($dbh) = &db_connect($data_source, $username, $passwd);

sub db_connect {
        my($source,$user,$pass) = @_;
        my($dbh) = DBI->connect($source, $user, $pass);

sub db_query {
        my($sel,$h) = @_;
        my($row,$sth) = undef;
        $sth = $h->prepare($sel);
        print "Names:      @{$sth->{NAME}}\n";
        print "Fields:     $sth->{NUM_OF_FIELDS}\n";
        print "Params:     $sth->{NUM_OF_PARAMS}\n";
        print "\nUid\tName\tType\n";

        while($row = $sth->fetch) {
           printf "%5i %-25s %-2s\n", @$row[0], @$row[1], @$row[2];

Expert Comment

ID: 8166862
I am gathering that you mean you want to access a Sybase server using Perl.

The Perl DBI is the best way to go about it - the example that was posted earlier was from that.

There are a lot of good books out there for starting out with perl - check the O'Reilly books for some of the best.  Learning Perl and Programming Perl are good starting points.  Also from the same group is Programming the Perl DBI.

Expert Comment

ID: 8733963
You can try this code

#!perl5/PROJ/core/5.005/exec/bin/perl ##Perl location u can obtain this by typing "which perl" at the prompt

use Sybase::DBlib;
$user = 'username';
$pwd = 'password';
$server = 'servername';
$database = 'databasename';


$dbh = Sybase::DBlib->dblogin($user, $pwd , $server);

die "Login failed!\n" if($DB_ERROR);

die "Cannot change to $database.\n" if($DB_ERROR);

$sql = "SELECT * FROM sysobject where type = 'u'"; # will give u the list of tables

die "Cannot execute $sql.\n" if($DB_ERROR);
$status = $dbh->DBROWS;
print "No Data for the query .\n" if ($status != SUCCEED);
die "Cannot retrieve result set.\n" if($DB_ERROR);
print " Name \n";
while(@db=$dbh->dbnextrow) {
        print "$db[0]\n";


sub myErrHnd {
        my ($db, $severity, $error, $os_error, $error_msg, $os_error_msg) = @_;
        print "Error : $error_msg \n";

sub myMsgHnd {
        my ($db,$message,$state,$severity,$text,$server,$procedure,$line) = @_;
        print "Message : $db,$message,$state,$severity,$text,$server,$procedure,$line\n";

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
I originally wrote this article to compare SARDU and YUMI, but have now added Easy2Boot, since that is the one I currently use and find the easiest to create and alter.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question