Solved

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

Posted on 2014-10-21
4
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

696 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