Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2014-10-21
Medium Priority
Last Modified: 2014-10-21

My page has the following SQLDataSource

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

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:

      dsResults.SelectCommandType = SqlDataSourceCommandType.Text
      dsResults.SelectCommand = BuildMasterQuery()
    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?
Question by:rpm
  • 2
  • 2
LVL 27

Expert Comment

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: " & _
End Sub

Open in new window


Author Comment

ID: 40394725
Ok this approach looks promising.

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

LVL 27

Accepted Solution

Sammy earned 2000 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

Author Comment

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

571 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