[Dbix-class] Detecting connection errors

Dagfinn Ilmari Mannsåker ilmari at ilmari.org
Wed Oct 14 17:09:44 GMT 2015


Alberto Luaces <aluaces at udc.es> writes:

> Hi,
>
> I stumped over a problem when learning to use DBIx::Class.  I had a typo
> on the filename holding the database, but no exception was thrown until
> I wanted to retrieve some results, which was not intuitive for me.  How
> do you check for a successful connection?

First of all, you never need to do "or die ..." with DBIx::Class
operations, since they always throw exceptions on error.

Sencondly, DBIx::Class only hits the database when it absolutely has to,
e.g. to fetch restults.  This includes the initial connection.  However,
you can force it to connect early by calling

   $schema->storage->ensure_connected;

Which will throw an exception if it fails to connect.

-- 
"The surreality of the universe tends towards a maximum" -- Skud's Law
"Never formulate a law or axiom that you're not prepared to live with
 the consequences of."                              -- Skud's Meta-Law




More information about the DBIx-Class mailing list