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

I have installed DBD::Sybase and FreeTDS to connect MS SQL Server from my linux box. It works, but I have to connect mirrored database instances. Because I have no clue which mirror is active, I try to connect all mirrors; when I connect the active mirror, all is OK, but when I try to connect non-active mirror, DBD driver prints following message to stderr, even though I have used {RaiseError=>1,PrintError=>0,PrintWarn=>0,AutoCommit=>0} attributes and connect method is called in eval{} section:
DBD::Sybase - can't change context to database DBNAME
Does somebody know how to suppress that message?

Replies are listed 'Best First'.
Re: How to suppress print connection error to stderr
by mpeppler (Vicar) on Feb 27, 2008 at 15:39 UTC
    The problem is that you specify the database name in the connect() call. DBD::Sybase attempts to "use" the database, and when that fails it reports the error. This is done early in the processing, and DBD::Sybase doesn't correctly handle the PrintError/RaiseError flags at that point (because they get set later in the process).

    Suggestion: don't specify the database in the DBI->connect() call, and instead run a $dbh->do("use DBNAME") right after the connect. This will properly handle the PrintError/RaiseError settings.

    Michael