E
Eagle
First I tried using the try, catch, throw, but it errored on the throw and I
don't want it to stop there, I want it to stop in the frm, not the class.
Next I set a Session to catch the error, and now I want to set the error
message label, but the error message label in teh form never appears. When
I stop the procedure and check to see if it's visible, it's true. It also
returns that the text says "Sql database doesn't exist" when sql is stopped.
So why does it not display the error?
form, page load:
cls.GetConnection
If Session("Error") <> "" then
lblError = cls.MessageLabel("ShowStopper")
Exit Sub
End If
Class:
Private Function GetConnection(ByVal connectionString As String) As
SqlConnection
Dim connection As New SqlConnection(connectionString)
connection.Open()
Return connection
End Function
Public Sub CheckConnection
Dim cnnSqlConn As SqlConnection = Nothing
Try
cnnSqlConn = GetConnection(mstrSQLConn)
Catch ext As Exception
'Throw New Exception("The connection with the database can´t be
established;" & ext.Message)
HTTPContext.Current.Session("Error") = ext.message
Finally
If Not cnnSqlConn Is Nothing Then
CType(cnnSqlConn, IDisposable).Dispose()
End If
End Try
End Sub
Public Function MessageLabel(strType as string) as label
Dim lbl as new label
Select Case strType
Case "ShowStopper"
lbl.Visible=True
lbl.Text = HTTPContext.Current.Session("Error")
lbl.ForeColor = Color.red
lbl.Font.Bold = true
End Select
Return lbl
End Function
don't want it to stop there, I want it to stop in the frm, not the class.
Next I set a Session to catch the error, and now I want to set the error
message label, but the error message label in teh form never appears. When
I stop the procedure and check to see if it's visible, it's true. It also
returns that the text says "Sql database doesn't exist" when sql is stopped.
So why does it not display the error?
form, page load:
cls.GetConnection
If Session("Error") <> "" then
lblError = cls.MessageLabel("ShowStopper")
Exit Sub
End If
Class:
Private Function GetConnection(ByVal connectionString As String) As
SqlConnection
Dim connection As New SqlConnection(connectionString)
connection.Open()
Return connection
End Function
Public Sub CheckConnection
Dim cnnSqlConn As SqlConnection = Nothing
Try
cnnSqlConn = GetConnection(mstrSQLConn)
Catch ext As Exception
'Throw New Exception("The connection with the database can´t be
established;" & ext.Message)
HTTPContext.Current.Session("Error") = ext.message
Finally
If Not cnnSqlConn Is Nothing Then
CType(cnnSqlConn, IDisposable).Dispose()
End If
End Try
End Sub
Public Function MessageLabel(strType as string) as label
Dim lbl as new label
Select Case strType
Case "ShowStopper"
lbl.Visible=True
lbl.Text = HTTPContext.Current.Session("Error")
lbl.ForeColor = Color.red
lbl.Font.Bold = true
End Select
Return lbl
End Function