Solved

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

Posted on 2014-10-21
4
460 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 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