Solved

ASP.Net VB Redirecting to an error page on SQLDataSource timeout

Posted on 2014-10-21
4
451 Views
Last Modified: 2014-10-21
Hi,

My page has the following SQLDataSource

<asp:SqlDataSource ID="dsResults" runat="server"
    ConnectionString="<%$ ConnectionStrings:Activist_InsightConnectionString %>"
    EnableViewState="False" >
</asp:SqlDataSource>

At the moment I am setting the timeout to be very low to force at timeout, ultimatly this number will be higher.

Protected Sub dsResults_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles dsResults.Selecting

    e.Command.CommandTimeout = 12

  End Sub

I want a friendly error page if the Query times out, so I tried the following:

Try
      dsResults.SelectCommandType = SqlDataSourceCommandType.Text
      dsResults.SelectCommand = BuildMasterQuery()
      dsResults.DataBind()
    Catch sqlEx As SqlException
      Response.Redirect("SearchTimeout.aspx?queryid=" & Request.QueryString("queryid"))
    Catch Ex As Exception
      Response.Redirect("SearchTimeout.aspx?queryid=" & Request.QueryString("queryid"))
    End Try


However when the query times out I do not redirect to the speciifed page, but I get an ASP.net error page.

What am I doing wrong?
0
Comment
Question by:rpm
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 40394531
This type of error has to be handled by the application error handler.
The event must be created in your global.ascx
from http://msdn.microsoft.com/en-us/library/vstudio/994a1482(v=vs.100).aspx
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    Session("CurrentError") = "Global: " & _
        Server.GetLastError.Message
    Server.Transfer("lasterr.aspx")
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:rpm
ID: 40394725
Ok this approach looks promising.

How do I tell if the error has come from the page that I am interested in?

Richard
0
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 40394809
in the application error event use something like this

Dim con As HttpContext = HttpContext.Current
con.Request.Url.ToString() 'will contain the page throwing the exception
0
 
LVL 1

Author Comment

by:rpm
ID: 40394853
That's done the trick, thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now