Asp.net Catch Database Error
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards exception handling in asp.net c# Events Community Magazine Forums Blogs Channel 9 Documentation APIs and
Asp.net Error Handling
reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. asp.net custom error You’ll be auto redirected in 1 second. MSDN Library MSDN Library MSDN Library MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development asp.net error page .NET Development Office development Online Services Open Specifications patterns & practices Servers and Enterprise Development Speech Technologies Web Development Windows Desktop App Development TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being
Asp.net Error Logging
maintained. Complete Example for Error Handlers Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 This code example includes elements for both page-level and application-level exception handling. Code Example Files The example consists of the following files: Web.config Global.asax Default.aspx ExceptionUtility (to be put in the App_Code folder) GenericErrorPage.aspx HttpErrorPage.aspx Http404ErrorPage.aspx DefaultRedirectErrorPage.aspx Web.config The following example shows the Web.config file. The customErrors section specifies how to handle errors that occur with file types that are mapped to ASP.NET, such as .aspx, .asmx, and .ashx files. (In IIS 6.0 and in IIS 7.0 in classic mode, static content files such as .html and .jpg files are not mapped to ASP.NET.) The settings in the example customErrors section cause any unhandled HTTP 404 (file not found) errors to be directed to the Http404ErrorPage.aspx file. These HTTP 404 errors would occur if a request were made for an .aspx file, .as
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about asp.net mvc error handling hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask asp.net error handling best practices Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Asp.net Application_error
Join them; it only takes a minute: Sign up ASP.NET Database Error Trapping up vote 0 down vote favorite I am curious as to how people trap certain database errors in .NET, particulary foreign key or unique index violations. https://msdn.microsoft.com/en-us/library/bb397417.aspx Coming from a Classic ASP/VB background, my first inclination is to test the error number to then create a friendly message to the user that something is wrong. However, I would think that in the .NET world, there would be things like a SqlForeignKeyException or similar. If such a thing exists, I cannot find it in the documentation anywhere. How do you handle such errors? .net ado.net exception-handling share|improve this question asked May 9 '09 at 17:20 BradBrening http://stackoverflow.com/questions/843693/asp-net-database-error-trapping 4,1191628 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted If your application is generating Foreign Key or Unique Index violations, there might be something wrong with the App, and its the developers you need to notify about it, not the users. That is, normally validation of the input the user is giving should prevent these sorts of exceptions from being thrown. A common approach is to catch unhandled errors in the Application_Error event, and log them to a file or database. Also there are tools that can help with error logging, such as ELMAH For the user, just a generic message would do ... but the Developers should be keeping an eye on the error logs. See Jeff Atwood's post on Exception Driven Development. Edit: To answer the other part of your question - there are a variety of different Exception objects in .NET, but most SQL Exceptions seem to come through as a generic SqlException class. You find out more about the errors by examining the Message and StackTrace() properties, and also drilling down into the InnerException property. Something like a Foreign Key violation might manifest itself as an HttpException with a SqlException nested inside it. share|improve this answer edited May 9 '09 at 17:32 answered May 9 '09 at 17:26 codeulike 11.6k1592144 A good example of what I mean would be for
- Life Cycle ASP.NET - First Example ASP.NET - Event Handling ASP.NET - Server Side ASP.NET - Server Controls ASP.NET - HTML Server ASP.NET - Client Side ASP.NET - Basic Controls https://www.tutorialspoint.com/asp.net/asp.net_error_handling.htm ASP.NET - Directives ASP.NET - Managing State ASP.NET - Validators ASP.NET - Database Access ASP.NET - ADO.net ASP.NET - File Uploading ASP.NET - Ad Rotator ASP.NET - Calendars ASP.NET - Multi Views http://www.4guysfromrolla.com/articles/081209-1.aspx ASP.NET - Panel Controls ASP.NET - AJAX Control ASP.NET - Data Sources ASP.NET - Data Binding ASP.NET - Custom Controls ASP.NET - Personalization ASP.NET - Error Handling ASP.NET - Debugging ASP.NET asp.net error - LINQ ASP.NET - Security ASP.NET - Data Caching ASP.NET - Web Services ASP.NET - Multi Threading ASP.NET - Configuration ASP.NET - Deployment ASP.NET Resources ASP.NET - Quick Guide ASP.NET - Useful Resources ASP.NET - Discussion Selected Reading Developer's Best Practices Questions and Answers Effective Resume Writing HR Interview Questions Computer Glossary Who is Who ASP.NET - Error Handling Advertisements Previous Page Next asp.net error handling Page Error handling in ASP.NET has three aspects: Tracing - tracing the program execution at page level or application level. Error handling - handling standard errors or custom errors at page level or application level. Debugging - stepping through the program, setting break points to analyze the code In this chapter, we will discuss tracing and error handling and in this chapter, we will discuss debugging. To understand the concepts, create the following sample application. It has a label control, a dropdown list, and a link. The dropdown list loads an array list of famous quotes and the selected quote is shown in the label below. It also has a hyperlink which has points to a nonexistent link. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="errorhandling._Default" %>