Handle EntityCommandExecutionException and show error message - wpf

When I make a change in the database (add, delete, rename a column) and don't update my EF mappings, I get an exception while in debug mode
System.Data.Entity.Core.EntityCommandExecutionException
but I don't see this exception caught in the Global DispatcherUnhandledException even if I catch and throw it from the code where the exception is occuring. What is the reason? Basically I want to validate my EF mappings when my application loads and if there is any mismatch in mapping I want to show user a friendly message that Client Application needs to be updated.

An option would be to create a command interceptor. This concept was introduced in Entity Framework 6.0.
You create the interceptor by implementing the IDbCommandInterceptor interface and then register it either through code or configuration.
http://www.tutorialspoint.com/entity_framework/entity_framework_command_interception.htm
http://www.entityframeworktutorial.net/entityframework6/database-command-interception.aspx
https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/connection-resiliency-and-command-interception-with-the-entity-framework-in-an-asp-net-mvc-application

Related

Trigger execution warnings with Logic App Standard on Azure Function Runtime

I've got a Logic App (Standard) running on an Azure Function runtime, and I've noticed I'm getting spammed with warnings for my O365 When a new email arrives in a shared mailbox (V2) trigger.
Trigger is meant to execute on cluster type 'Classic'. However, it is executing on cluster 'NotSpecified'
Just Created a Logic App (Standard) and created an O365 trigger on a shared mailbox v2 trigger.
Allowed the trigger to fire
Log Stream/AppInsights will show the warning about trigger execution: Trigger is meant to execute on cluster type 'Classic'. However, it is executing on cluster 'NotSpecified'
There can be several reasons for the error that is mentioned above. One way to solve this problem is by reconfiguring the O365 Logic App Connection and try again.
Usually it happens when there is a version mismatch of the library reference or older version of the component referenced in logic app. If still the error persist, error handling need to be implemented properly in logic apps to get detailed error. App Insight will give proper error log and provide us the error logs if issue still persist.
Please check this Handle errors and exceptions in Azure Logic Apps documentation from Microsoft for more information.

SqlDependency not working

I'm using EF 6 with SQL Server 2012.
I'm trying to use SqlDependency to refresh my cached data, in a class library (DLL).
I have the following, based on whatever guides I found, but seems like it is not working, and I get no error.
enabled broker service on the db
created the broker queue, and the service
Using sa login.
I'm testing this whole thing through unit testing code, not sure maybe the notification is not instantaneous, my breakpoint in SqlDependency.OnChange never triggered.
But even if I purposely slow down the post-changes, OnChange is still not triggered.
Once I made relevant data changes, how can I know SQL Server is generating a notification in db?
Update:
Initially I found "master key encryption is required" in SQL log. By creating that key, the log no longer happened, but OnChange is still not triggered.
After many trials, and based on 1 important article:
http://www.codeproject.com/Articles/12335/Using-SqlDependency-for-data-change-events
1) After SqlDependency is initialized, must execute the SqlCommand, can simple just invoke sqlCmd.ExecuteNonQuery().
2) After OnChange event triggered, must remove the event handling, recreate a new SqlCommand and SqlDependency, rebind the event handling, and follow rule #1

Ektron and Elmah - 404 Errors not being logged

I am currently configuring ELMAH 1.2 to log errors within our Ektron 9.1 application, however it will not log any 404 errors. ELMAH is currently functional as it is logging other errors (including unhandled exceptions), just not 404 errors. I am not running an MVC environment / 3-Tier Ektron Architecture, we are still using the traditional ASP.NET / Ektron Web Forms solution.
I know ELMAH logs these errors by default, so I'm wondering if I'm missing something with regards to how ELMAH is interacting with Ektron. There's not much information out there on the topic, and the one article I found is dated from 2010, so the information is severely outdated.
It's different for URLs that end in .aspx and other ones. If a user goes to your site and accesses /ThisFileisnothere.html The static file handler would handle that. Ektron replaces the static file handler with the EkDavHttpHandlerFactory. Ektron's handler doesn't throw an exception. It doesn't trigger an Application.Error Event. It just sets the statusCode to 404. If you wanted to do something custom like log an error to ELMAH, you could hook the Application.PostRequestHandlerExecute and check the Response.StatusCode
If a user tries to go to /ThisPageisntHere.ASPX then a different handler will handle that URL and will trigger the Application.Error event that ELMAH should catch.

CakePHP: Send emails for crashes

What's the best way to add email notifications for CakePHP crashes? I want to be emailed with a stacktrace whenever a fatal error occurs, so that I can know immediately instead of checking the logs.
I looked at overriding AppController::appError(); but I don't want to replace all of the exception handling.
Check this out, it is to long to paste here.
https://github.com/CakeDC/utils/blob/develop/Error/EmailErrorHandler.php
It is a customized error handler for CakePHP. You need to configure CakePHP to use that error handler class. My pull request to the core was rejected that introduced an Event in the handleError() method... An event there would make it really easy to handle use cases like this.

Handling DataAccessException in Spring Security

Right now I've got Spring Security protecting an application using basic authentication. The user details are coming from a JDBC source. If the database goes down, the internals of the user loading mechanism will throw a DataAccessException. The default authentication provider class, DaoAuthenticationProvider, catches the exception and maps it back to an AuthenticationServiceException. The end result of such a mapping is that the browser/client receives HTTP code 401.
What I want to do is to handle database unavailability in a different way. At the very least, I want this to be handled by responding with HTTP 503 but I would prefer if it redirected to an error page. How can I achieve this?
EDIT: Ritesh's solution was partially correct. The missing steps apart from implementing your own Basic entry point is to also use v3.0.3 of the security schema so that the <http-basic/> element has the entry-point-ref attribute. If you don't use this special attribute, the default Basic filter will always use its own Basic entry point implementation.
The BasicAuthenticationEntryPoint sends 401 for AuthenticationException. You can create your own custom entry point to handle AuthenticationServiceException and send out 503.
Other option is not to do anything in entry point and use SimpleMappingExceptionResolver and/or implement your own HandlerExceptionResolver.

Resources