About

I'm Mike Pope. I live in the Seattle area. I've been a technical writer and editor for over 35 years. I'm interested in software, language, music, movies, books, motorcycles, travel, and ... well, lots of stuff.

Read more ...

Blog Search


(Supports AND)

Feed

Subscribe to the RSS feed for this blog.

See this post for info on full versus truncated feeds.

Quote

Of course, the only practical use of the en dash is as subtle code to communicate, from one publishing professional to another, the abstract concept, "I am copy editor. Hear me roar." Recognizing the en dash can be like a secret handshake to our club.

"Editor", commenting on the "Subversive Copy Editor" blog



Navigation





<April 2025>
SMTWTFS
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Categories

  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  
  RSS  

Contact Me

Email me

Blog Statistics

Dates
First entry - 6/27/2003
Most recent entry - 9/4/2024

Totals
Posts - 2655
Comments - 2678
Hits - 2,734,248

Averages
Entries/day - 0.33
Comments/entry - 1.01
Hits/day - 344

Updated every 30 minutes. Last: 10:05 AM Pacific


  04:57 PM

In a comment on another post about validating parameters for the SqlDataSource control, someone asks about how to handle errors that might occur within the SqlDataSource control -- e.g. "query timeout, SQL Server not running, mistake in query," to quote the comment. I thought it was worthwhile to promote the discussion from the comments to a separate entry. (If you read those comments, there's nothing new here for you ...)

Eilon confirmed that the data source controls don't raise their own error events. You can trap errors like the ones listed, but you have to do so slightly indirectly.

You have (at least) two choices. One is to perform data binding yourself and put the DataBind call into a try-catch block:
Sub Page_Load()
If Not IsPostBack Then
Try
GridView1.DataSourceID = "SqlDataSource1"
GridView1.DataBind()
Catch ex As Exception
' Hopefully better error handling that this ...
Response.Write("Error data binding")
End Try
End If
End Sub
You can also catch the error in the Page_Error handler (documented here). Handle the Page_Error event and then redirect (using Server.Transfer) to an error page. Here's the handler:
Sub Page_Error()
Server.Transfer("DataBindError.aspx")
End Sub
And a possibility for the target page:
Sub Page_Load()
Label1.Text = Server.GetLastError.Message
End Sub
This will catch all unhandled errors in the page, which I guess is a good thing or a bad thing, depending.

PS You can also create an application-level error handler. (#)

[categories]   ,

[3] |