Asp.net ASP NET在出错后停止执行其他子进程

Asp.net ASP NET在出错后停止执行其他子进程,asp.net,vb.net,Asp.net,Vb.net,我的try-catch块运行出现错误: database is not available 我的问题是try-catch运行并捕获错误,但它不会重定向到我的错误页面。代码继续执行其他子类。我尝试添加:退出,返回,响应。结束。他们都没有工作。谢谢你的帮助 Imports System.Data Imports EUC Imports System.Threading Imports System.Data.SqlClient Partial Class

我的try-catch块运行出现错误:

database is not available
我的问题是try-catch运行并捕获错误,但它不会重定向到我的错误页面。代码继续执行其他子类。我尝试添加:退出返回响应。结束。他们都没有工作。谢谢你的帮助

    Imports System.Data
    Imports EUC
    Imports System.Threading
    Imports System.Data.SqlClient

    Partial Class mpMain
        Inherits System.Web.UI.MasterPage

        Dim strSQL As String
        Dim objData As clsDataAccess = New clsDataAccess()
        Dim ds As New D

ataSet
    Dim t1 As DataTable
    Dim intSecurityLevel As String = 0
    Dim strUser As String = UCase(Right(HttpContext.Current.User.Identity.Name.ToString(), 4))

    Protected Sub ExpandNode(ByVal NodeName As String, ByVal PageName As String)

    'More Code

    End Sub


    Protected Sub ExpandNode2(ByVal NodeNameMain As String, ByVal NodeName As String, ByVal PageName As String)

    'More Code

    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


            If Not (IsPostBack) Then

                Try
                    strSQL = "Select SecurityLevel from tblSecurity where SFID = @SFID order by SecurityLevel"

                    Dim MyParameters1 As SqlParameter() = { _
                        New SqlParameter("@SFID", SqlDbType.VarChar) _
                    }

                    MyParameters1(0).Value = UCase(Right(HttpContext.Current.User.Identity.Name.ToString(), 4))

                    ds = objData.SQLExecuteDataset(strSQL, CommandType.Text, MyParameters1)

                    t1 = ds.Tables(0)

                Catch ex As Exception

                    Dim sendError As New clsExceptionMessage
                    sendError.sendMessage(ex.Message, Request.Path, strSQL)
                    Response.Redirect("ErrorMessage.aspx", False)

                End Try

            End If

    End Sub

    Protected Sub TreeView1_TreeNodeDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeDataBound

    'More Code

    End Sub


    Protected Sub TreeView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.DataBound

    'More Code

    End Sub


End Class

首先,我将捕获SQLException,您很少希望捕获一般异常

在catch块中,设置一个布尔参数,例如

hasError = True

一旦超出try..catch块检查,检查是否为真,并从此处重定向。

嗨,Justin,我尝试了更改,但它仍然执行其他子命令。尝试将hasError作为全局参数(Dim hasError作为布尔值)放在Dim strUser下,然后将其作为每个子命令的第一部分进行检查,以获得帮助。数据访问类是它第一次无法工作的罪魁祸首。