0

I have a Winforms application that uses SQL Server in the cloud. Have Dapper handling the data side. I wrapped all my data calls in a try/catch and bubble them up. However, they are sync methods and was thinking about moving to async but the user will just click multiple times with no feedback.

What are the best practices in handling this configuration and should I try to ping the database before each call and then if that returns true execute the method to perform the data operation?

It takes about 30 seconds response if the connection fails and throws a transport error. For example if someone enables or disables a VPN then the connection will be down for a few seconds or where they sleep the computer.

It would be nice to get a message about being offline before performing any actions.

How to efficiently check for a line to the database and handle the result?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Zippy
  • 455
  • 1
  • 11
  • 25
  • The result of a ping tells nothing about the availability of the DB. Just issue the connection, maybe with a shorter timeout, catch the **specific** exception and display the error accordingly. – Alejandro May 05 '21 at 16:42
  • As for the user clicking multiple times while the operation is in progress, use some sort of "loading" indicator, disable the button and shape the rest of the UI to clearly indicate a operation is in progress, optionally restricting what the user can do while waiting. – Alejandro May 05 '21 at 16:43
  • 1
    If you expect semi-regular 30 second outages due to network connection changing, you might consider using something like [Polly](https://github.com/App-vNext/Polly) to wrap the database calls in a retry strategy. That way it automatically recovers from such an issue. I also second Alejandro's comments. – mason May 05 '21 at 16:50
  • i like the idea of polly. looking to just do an async call every 30 sec select 1 and if I get back 1 then online. but looks like with polly i can queue the inserts and modifies and move my datagrid to more of a complete in memory grid and handle changes then when online reconsile. – Zippy May 05 '21 at 17:08

0 Answers0