0

When I don't have a VPN connection to my office, I need to throw an exception that says you are not connected, and I am struggling to catch that exception.

Here is a screenshot:

68 uncatchable SqlException
(Click image to enlarge)

karel
  • 5,489
  • 46
  • 45
  • 50
E.Murat
  • 1
  • 1
  • Welcome to stackoverflow. Please take a minute to take the [tour], especially [ask], and [edit] your question accordingly. – jazb Nov 21 '18 at 07:08
  • That Exception though is in your regional language - seems like "Named Pipes Provider Error 40 - Could Not Open A Connection To SQL Server" Error. Check this: https://stackoverflow.com/questions/9945409/how-do-i-fix-the-error-named-pipes-provider-error-40-could-not-open-a-connec – Prateek Shrivastava Nov 21 '18 at 08:00
  • @PrateekShrivastava ty for support but I know what is this error about. The app can't reach server and database. I dont want to solve it, just want to pop messagebox that says check your connection. It already works after 68 exception. But you can imagine my app crushes while at this loop so for it my main goal is catch first exception and throw message. – E.Murat Nov 21 '18 at 09:10
  • Are you sure your exception isn't being caught? Note that the IntelliTrace window shows all exceptions, not just unhandled ones. – Maciej Stachowski Nov 21 '18 at 11:51

1 Answers1

0

Not Sure if I get you completely - But your For loop runs 68 times (is that what you mean) and then the Exception is thrown. Which you want to be handled way before so that For Doesnt run. My Guess is that you have Entity Framework. So your code gets the Exception when it actually tries to connect to DB. May be try:

MyDbContext.Database.Exists(); before you run the Loop. See if that returns Bool or throws Exception since server unreachable.

Prateek Shrivastava
  • 1,877
  • 1
  • 10
  • 17
  • No I dont have For loop. I think EF drops to a loop. The problem already about MyDbContext. MyDbContext tries to use connectionString and cant reach database again again and again. I think there is no way to catch first exception and throw, app must crush for a while ? – E.Murat Nov 21 '18 at 09:46