Try/Catch を使用して、データベースへの潜在的な失敗した接続を処理しようとしています。Catch セクションに Response.Redirect コマンドがあります。ページが読み込まれるたびに、Try セクションのコードが失敗するかどうかに関係なく、Catch セクションに従ってリダイレクトされます。
Catch セクションの Response.Redirect コマンドをコメント アウトすると、ページが正常に読み込まれます。同様に、Response.Redirect コマンドをコードに置き換えて、想定されるエラーがトラップされた状態でページ上のコントロールを設定すると、Try セクションは成功します。これは、Catch セクションに Response.Redirect があることに関するものです...
Private Sub Page_Load(Sender As Object, e As eventargs) Handles Me.Load
Try
Dim sqlcon As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("SarcoidsConnectionString").ConnectionString)
Dim cmd As New System.Data.SqlClient.SqlCommand("SELECT PortalEnabled FROM [tlkSettings]", sqlcon)
sqlcon.Open()
Dim dbReader As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
If dbReader.HasRows Then
While dbReader.Read()
If dbReader("PortalEnabled") = True Then
Response.Redirect("~/SubmitWizard.aspx")
Else
Response.Redirect("~/Maintenance.aspx")
End If
End While
End If
sqlcon.Close()
Catch ex As Exception 'Display Maintenance page if database cannot be connected to
Response.Redirect("~/Maintenance.aspx")
End Try
End Sub