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
Solved

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

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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