Asp.net Datasource Error Handling
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and asp.net error handling policies of this site About Us Learn more about Stack Overflow the
Exception Handling In Asp.net C#
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users asp.net error page Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes asp.net mvc error handling a minute: Sign up How to catch error while inserting data with SqlDataSource up vote 0 down vote favorite I have a SqlDataSource and a GridView. What I want to do is, while the query is executed (i.e. for inserting a data), then after the data has inserted successfully, it should appear a message sounds: "The data deleted successfully". I've solved
Asp.net Error Logging
it by using GridView1_RowDeleted method. Now the problem is, I want to catch the error while the query is failed to executed. If the query has failed to execute, then it should appear a message: "The data failed to insert.". How to do it? I don't have an idea about this. Need your help guys. Thanks a lot. vb.net try-catch sqldatasource share|improve this question asked Oct 30 '11 at 3:36 mrjimoy_05 1,41742764 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted You should be able to add a handler for the relevant event: inserted, deleted. Then, in the handler look at the SqlDataSourceStatusEventArgs property Exception. If it's not null then an exception has occurred. For example if the selected command threw an exception: protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e) { if (e.Exception != null) { // handle the exception } } -- share|improve this answer answered Oct 30 '11 at 14:48 Enigma State 11.2k1561114 hey it's worked!! :) . I've tried to change the handler become: Protected Sub SqlDataSource1_Updated(sender As Object, e As System.Web.UI.WebControls.S
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/Data Access/DataSource Controls - SqlDataSource, ObjectDataSource, etc/Error Handling with SQLDataSource Error Handling with SQLDataSource asp.net custom error [Answered]RSS 7 replies Last post May 26, 2009 11:05 AM by page_error event in asp.net c# grayboat ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved
Asp.net Application_error
Threads Support Options Advanced Search Reply mistry_bhavi... Member 1 Points 330 Posts Error Handling with SQLDataSource Apr 04, 2006 08:50 AM|mistry_bhavin|LINK Hello to all I am having http://stackoverflow.com/questions/7943173/how-to-catch-error-while-inserting-data-with-sqldatasource a SQLDataSource on my web page to connect with database. Now If it generates any error then where to capture that errors ?? Means at which place(which event or any other place) should i write code for handeling errors ??? Reply Iori_Jay Star 9041 Points 2449 Posts Re: Error Handling with SQLDataSource Apr 10, 2006 05:00 http://forums.asp.net/t/978920.aspx?Error+Handling+with+SQLDataSource AM|Iori_Jay|LINK Which programming language (e.g. C#) do you use for your web page? In C#, you can use a 'try...catch' block to catch the exception when connect to SQLDataSource; you canperform the connection action in a 'button click' event or in page load event as you like. Welcome to my SQL/ASPNET forum for Chinese http://51up.org/bbs/forumdisplay.php?fid=38 Reply mistry_bhavi... Member 1 Points 330 Posts Re: Error Handling with SQLDataSource Apr 10, 2006 06:54 AM|mistry_bhavin|LINK Yes I know in C# I can use Try---catch. But on which event Do I use Try and Catct ? If I use this on "selecting " it does not have any effect... Reply sb701 None 0 Points 9 Posts Re: Error Handling with SQLDataSource Apr 20, 2006 12:18 PM|sb701|LINK Yeah im also wondering how to do this. The sql data source is loaded when the page loads and runs the select command, so it is not run when a button is pressed. Reply mpswaim Member 10 Points 109 Posts Re: Error
Unanswered Topics Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics SqlDataSource - Error Handling? User Name Remember Me? Password Reminder Password Register Register | FAQ | Members List | Calendar | Today's Posts | Search ASP.NET http://p2p.wrox.com/asp-net-2-0-basics/48187-sqldatasource-error-handling.html 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. Search Forums Show Threads Show Posts http://help.infragistics.com/Help/Doc/ASPNET/2011.1/CLR4.0/html/WebGrid_Handling_CRUD_Errors_with_a_SQL_Data_Source.html Advanced Search Find All Thanked Posts Go to Page... Welcome to the p2p.wrox.com Forums. You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands error handling of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free . Thread Tools Display Modes #1 (permalink) September 22nd, 2006, 01:30 PM RobC Authorized User Join Date: Jan 2006 Location: in asp.net c# , , . Posts: 41 Thanks: 0 Thanked 0 Times in 0 Posts SqlDataSource - Error Handling? I've got a bunch of ASP.NET books which cover this control, but none of them discuss error handling. For example, what is the preferred method for handling a situation where you're trying to do a query through a SqlDataSource object, but the database server is temporarily down? In doing a Google search, I see that this a common question, but there doesn't seem to be any consensus as to how to handle this. It also seems like an oversight on Microsoft's part that there are no built-in error events for the control. What I'm really trying to figure out is: if you're creating a public web site and you want it to be bullet-proof, should you not use this control and just stick to code for database connectivity? #2 (permalink) September 23rd, 2006, 05:46 AM Imar Wrox Author Points: 70,499, Level: 100 Activity: 100% Join Date: Jun 2003 Location: Utrecht, Netherlands. Posts: 16,828 Thanks: 78 Thanked 1,535 Times in 1,512 Posts Hi Rob, You can hook into various events of the SqlDataSource control, like its Selected, Updated, Deleted events and so on. These events have an EventArgs argument that have an Exception property. This property is not null / nothing when an error occurred somehow. By diagnosing the excep
is bound to. However, SqlDataSource does not handle database errors that bubble up to a control through Create, Update, and Delete (CRUD) events; this process is left up to you. WebGrid™ makes it easier for you to handle these errors even when using LoadOnDemand. What You Will Accomplish You will learn how to bind WebGrid to SqlDataSource and use SqlDataSource’s events to handle database error. You will use WebGrid’s LoadOnDemand functionality to relegate error messages to the client. Follow These Steps Create an ASP.Net WebPage with WebGrid bound to a SqlDataSource component. For more information on how to do this, see Binding WebGrid To SQL Data Source. Be sure to select the Customers table with columns CustomerID, CompanyName, ContactName, and ContactTitle selected. Also, make sure SqlDataSource generates Update, Insert, and Delete statements. You can do this in the Configure the Select Statement part described in the topic linked above. Drag a ScriptManager onto the form. In the property window for WebGrid, set the following: Set the Browserproperty to Xml. Set the DataKeyField property to CustomerID Set the LoadOnDemand property under the DisplayLayout object to Xml. Make sure AllowAddNewDefault, AllowDeleteDefault, and AllowUpdateDefault under the DisplayLayout object is set to Yes. Set RowSelectorsDefault under the DisplayLayout object to Yes. Handle the Updated, Deleted, and Inserted events of SqlDataSource. You will use these events to catch database errors. Create a HandleError method to call when one of the above events is triggered. In this method, set the client response of WebGrid with information on the status of CRUD operations. In Visual Basic:Private Sub HandleError(ByVal e As SqlDataSourceStatusEventArgs) If e.Exception IsNot Nothing Then ' This information is available during the client side ' UltraWebGrid1_XmlHTTPResponseHandler event ' Set response status so client will know the status of update Me.UltraWebGrid1.ClientResponse.ResponseStatus = XmlHTTPResponseStatus.Fail ' The exception detail Me.UltraWebGrid1.ClientResponse.StatusMessage = e.Exception.Message ' The custom message for the client can be stored in the tag of the response Me.UltraWebGrid1.ClientResponse.Tag = _ "Update was not successful, check exception details for further information" e.ExceptionHandled = True Else Me.UltraWebGrid1.ClientResponse.Tag = "The process worked" End If End Sub
In C#:void HandleError(SqlDataSourceStatusEventArgs e) { if (e.Exception != null) { // This information is available during the client side // UltraWebGrid1_XmlHTTPRespo