Re: SQLClient Exception - Retrying

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Shawn Berg (shawn_at_saeweb.com)
Date: 02/15/05


Date: Tue, 15 Feb 2005 15:10:26 -0500

This app I am programming is not operated by a live user, but more of a
service app which needs to continually run uninterrupted no matter what
network problems may be occurring. When there are network problems,
timeouts, sql server is down, etc. I need the app to handle this gracefully
and process all remaining transactions when the problems are resolved. This
has to be done without any user intervention. This is why I want to retry no
matter what the error may be, and continue to do so until the problem is
resolved.

What is the best way to code this?

"William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message
news:#nA2HS5EFHA.1836@tk2msftngp13.phx.gbl...
> With timeouts, yes it makes sense to retry. With the other failures, it's
a
> waste of time. I would add code to test the viability of the LAN and SS
> connection and retry once they are back up. In the meantime I would inform
> the user that there are problems with the server and/or back off to a
> mirrored or backup server. This will be easy with Whidbey/Yukon and the
2.0
> Framework. It can be done now, but it's a bit harder.
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> __________________________________
>
> "Shawn Berg" <shawn@saeweb.com> wrote in message
> news:eD4poO5EFHA.4072@TK2MSFTNGP10.phx.gbl...
> > You are correct, but I do feel it is important to at least try a few
more
> > times before completely giving up. It won't hurt, right? And as far as
the
> > time goes, sometimes we get intermittent timeouts with our DB (very
rare,
> > but it does happen) and these I would definitely like to retry and 99%
of
> > the time they go through the second time around.
> >
> > Can you give me any suggestions as to how this can be accomplished?
> >
> > Shawn
> >
> > "William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message
> > news:eNdgVM5EFHA.3732@TK2MSFTNGP14.phx.gbl...
> >> Ah, if the server goes down the pooled connection will be corrupted and
> >> cannot be reused. You'll also have to wait a lot longer than 3 seconds
> >> for
> >> the server to restart. If you lose the network you have most of the
same
> >> issues. Putting an ADO operation in the Catch block is problematic--it
> > needs
> >> its own Try/Catch.
> >>
> >> --
> >> ____________________________________
> >> William (Bill) Vaughn
> >> Author, Mentor, Consultant
> >> Microsoft MVP
> >> www.betav.com
> >> Please reply only to the newsgroup so that others can benefit.
> >> This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> >> __________________________________
> >>
> >> "Shawn Berg" <shawn@saeweb.com> wrote in message
> >> news:%23Wcsq04EFHA.3636@TK2MSFTNGP09.phx.gbl...
> >> > Upon executing a stored procedure using the Data Access application
> >> > block's
> >> > SQLHelper class, I would like to continually retry to execute it
every
> >> > 1
> >> > second up to 3 times if an exception occurs. For example, if for some
> >> > reason
> >> > the database server is down, a timeout occurs, etc. I would like to
> >> > automatically retry a certain number of times before giving up. What
is
> >> > the
> >> > best way to accomplish this? Below is what I envision (pseudo-code):
> >> >
> >> > Dim Retries As Integer = 0
> >> > Dim
> >> >
> >> > Try
> >> > '// execute database command here
> >> > SQLHelper.ExecuteNonQuery(...)
> >> > Catch ex AS SQLException
> >> > If Retries <= 3 Then
> >> > Sleep(1000)
> >> > SQLHelper.ExecuteNonQuery(...)
> >> > End If
> >> > End Try
> >> >
> >> > The problem I have with the code above is that I have duplicate code
> >> > (SQLHelper.ExecuteNonQuery(...)). The other problem I have, is what
> >> > happens
> >> > when an exception occurs in the Catch block?
> >> >
> >> > Any help would be greatly appreciated.
> >> >
> >> > Thanks,
> >> >
> >> > Shawn
> >> >
> >> >
> >>
> >>
> >
> >
>
>



Relevant Pages

  • differing sizes of wchar_t
    ... It's actually done via libcurl but that doesn't matter here; the point is that I am presented with a void * pointing to a block of raw data and a long giving the number of bytes in the block, ... since my app comprises both server and client I know the data is line-oriented text. ...
    (comp.lang.java.softwaretools)
  • differing sizes of wchar_t (client vs server)
    ... My app reads text data over a socket. ... But for full generality I'd like the server to deliver text in the UCS-2 ... simple matter of transposing char to wchar_t and strlento wcslen, ... store them in a Unicode format (which is easy on the server side since ...
    (comp.unix.programmer)
  • Re: 1103 invalid seek offset error
    ... > We have a client that is running a VFP 8.0 app on a server, ... > on the server itself. ... "Retry" is all very well but this nasty white box steals focus from ... I'd hope they've fixed this in VFP by now but it's worth checking I guess: ...
    (microsoft.public.fox.programmer.exchange)
  • RE: Prevent ODBC connections
    ... If the user has access to the server and the database, ... then it doesn't matter what tool they use. ... The app would have to be ...
    (microsoft.public.sqlserver.connect)
  • Terminal Services and KB article 186499
    ... Registry Settings for Applications on a Win2003 server? ... It doesn't seem to matter what combination of bits I use ... my App takes absolutely no notice and still reports the PC ... the Win2KAdv Server. ...
    (microsoft.public.windows.server.general)