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

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

The deadly train derailment that occurred recently in DuPont, Washington, raises a lot of questions. It was a new route, the first trip tested with passengers, and the train was travelling at 50 mph over the zone’s speed limit. Could IoT play a role…
I’m willing to make a bet that your organization stores sensitive data in your Windows File Servers; files and folders that you really don’t want making it into the wrong hands.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

579 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