C# - Uncatchable Entity Framework SqlException












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)










share|improve this question

























  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask, and edit your question accordingly.

    – JohnB
    Nov 21 '18 at 7: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: stackoverflow.com/questions/9945409/…

    – Prateek Shrivastava
    Nov 21 '18 at 8: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 9: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
















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)










share|improve this question

























  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask, and edit your question accordingly.

    – JohnB
    Nov 21 '18 at 7: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: stackoverflow.com/questions/9945409/…

    – Prateek Shrivastava
    Nov 21 '18 at 8: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 9: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














0












0








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)










share|improve this question
















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)







c# entity-framework exception sqlexception






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 11:46









karel

2,19342631




2,19342631










asked Nov 21 '18 at 7:06









E.MuratE.Murat

11




11













  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask, and edit your question accordingly.

    – JohnB
    Nov 21 '18 at 7: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: stackoverflow.com/questions/9945409/…

    – Prateek Shrivastava
    Nov 21 '18 at 8: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 9: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



















  • Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask, and edit your question accordingly.

    – JohnB
    Nov 21 '18 at 7: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: stackoverflow.com/questions/9945409/…

    – Prateek Shrivastava
    Nov 21 '18 at 8: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 9: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

















Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask, and edit your question accordingly.

– JohnB
Nov 21 '18 at 7:08





Welcome to stackoverflow. Please take a minute to take the tour, especially How to Ask, and edit your question accordingly.

– JohnB
Nov 21 '18 at 7: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: stackoverflow.com/questions/9945409/…

– Prateek Shrivastava
Nov 21 '18 at 8:00







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: stackoverflow.com/questions/9945409/…

– Prateek Shrivastava
Nov 21 '18 at 8: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 9:10





@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 9: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





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 Answer
1






active

oldest

votes


















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.






share|improve this answer
























  • 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 9:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406864%2fc-sharp-uncatchable-entity-framework-sqlexception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer
























  • 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 9:46
















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.






share|improve this answer
























  • 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 9:46














0












0








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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 9:17









Prateek ShrivastavaPrateek Shrivastava

990512




990512













  • 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 9:46



















  • 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 9:46

















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 9:46





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 9:46




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406864%2fc-sharp-uncatchable-entity-framework-sqlexception%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()