I used Sybase DBlib to connect to a sybase erver and then use dbuse to change database. However, it displayed STDERR on the command prompt. Instead, I would like to capture the error and suppress them. Could you advise how to do?

sub generate_syboutput{ my $curr_dbserver=$_[0]; my $curr_db=$_[1]; $curr_db=~ s/\s//g; my $dbuser=$_[2]; my $dbpasswd=$_[3]; my $sp_name=$_[4]; my $fh=$_[5]; my $sqlcmd; my $dbh1=Sybase::DBlib->new($dbuser, $dbpasswd, $curr_dbserver); if (!$dbh1) { print "Connection Failed\n"; exit(0); } print "Debug Before dbuse\n"; if (!$dbh1->dbuse($curr_db)) { print "Debug this db cannot use\n"; } }

Output

Debug Before dbuse

Msg 10351, Level 14, State 1

Server 'MUTRDP3', Line 1

Server user id 2038 is not a valid user in database 'TestDB1'

DB-Library error: General SQL Server error: Check messages from the SQL Server.

Debug this db cannot use

I noticed there is dberrhandle or dbmsghandle that can be used for error handle but i don't know how to use it. please advice. do you have any example?


In reply to Handle DBlib error by tcheungcm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.