Forum: Ruby DBI Connect failure - can we retry please?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
428f1d76da99d9602d57b046841df29a?d=identicon&s=25 Dave Smith (railsnoob)
on 2009-05-26 14:29
Hi Guys,

I got a DBI connection that tries to connect to a source that sometimes
has an unreliable connection behind it.

  DBH = DBI.connect('dbi:ODBC:conenction_name', 'username', 'password')

It has failed a couple of times to connect and just bombs out the
script. As this is to be an automated script it would be nice to be able
to make a couple of attempts at trying to connect before bombing out.

Is anyone able to offer any code and advice as to how best to go about
this? I have looked online but the help is limited.

Many thanks in advance,

Roger
Ae82cad40a0caca9c932d45c7a9eb3cd?d=identicon&s=25 Michael Glaesemann (Guest)
on 2009-05-26 15:16
(Received via mailing list)
On May 26, 2009, at 8:29 , Dave Smith wrote:

> It has failed a couple of times to connect and just bombs out the
> script. As this is to be an automated script it would be nice to be
> able
> to make a couple of attempts at trying to connect before bombing out.
>
> Is anyone able to offer any code and advice as to how best to go about
> this? I have looked online but the help is limited.

begin/rescue with a counter?

Michael Glaesemann
grzm seespotcode net
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (djberg96)
on 2009-05-26 17:32
(Received via mailing list)
>
>   DBH = DBI.connect('dbi:ODBC:conenction_name', 'username', 'password')
>
> It has failed a couple of times to connect and just bombs out the
> script. As this is to be an automated script it would be nice to be
> able
> to make a couple of attempts at trying to connect before bombing out.
>
> Is anyone able to offer any code and advice as to how best to go about
> this? I have looked online but the help is limited.

gem install attempt

attempt{ dbh = DBI.connect(...) }

See http://rubyforge.org/docman/view.php/735/485/README.html for more
details.

Regards,

Dan
This topic is locked and can not be replied to.