G
gv
Hi all,
I'm trying to catch errors and when running in VS.net 2003 my try catch
doesn't seam to catch the error?
this error comes up: why does this not catch it?
Catch ex As System.Data.SqlClient.SqlException
"A first chance exception of type 'System.Data.SqlClient.SqlException'
occurred in system.data.dll
Additional information: System error."
my code is this:
Public Function RunSQLcmd(ByVal SQLquery As String, ByVal Msgtxt As String)
Dim result As String = String.Empty
Dim MessageFrm As StatMess = New StatMess
MessageFrm.StatusMessage(Msgtxt)
Try
' Reset the cursor to the hourglass postion.
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
SQLConnection(loginDatabase, loginIPaddress, "Standard",
loginuser, loginpass)
Dim MyCmd2 As New SqlCommand(SQLquery)
MyCmd2.CommandTimeout = 600
MyCmd2.Connection = SQLConn
SQLConn.Open()
MyCmd2.ExecuteNonQuery()
SQLConn.Close()
Application.DoEvents()
Catch ex As System.Data.SqlClient.SqlException
result = "There was an SqlException.." & vbCrLf & "Details..." &
vbCrLf & ex.ToString()
Catch ex As InvalidCastException
result = "There was an InvalidCastException..." & vbCrLf &
"Details..." & vbCrLf & ex.ToString()
Catch ex As Exception
result = "There was an Unhandled Exception..." & vbCrLf &
"Details..." & vbCrLf & ex.ToString()
Finally
If IsNothing(MessageFrm) = False Then MessageFrm.Dispose()
If IsNothing(SQLConn) = False Then
If SQLConn.State <> Data.ConnectionState.Closed Then
SQLConn.Close() : SQLConn.Dispose()
End If
MsgBox(result)
Cursor.Current = System.Windows.Forms.Cursors.Default
MessageFrm.close()
End Try
' Reset the cursor to the default for all controls.
Cursor.Current = System.Windows.Forms.Cursors.Default
SQLConn.Close()
MessageFrm.close()
End Function
thanks
Gerry
I'm trying to catch errors and when running in VS.net 2003 my try catch
doesn't seam to catch the error?
this error comes up: why does this not catch it?
Catch ex As System.Data.SqlClient.SqlException
"A first chance exception of type 'System.Data.SqlClient.SqlException'
occurred in system.data.dll
Additional information: System error."
my code is this:
Public Function RunSQLcmd(ByVal SQLquery As String, ByVal Msgtxt As String)
Dim result As String = String.Empty
Dim MessageFrm As StatMess = New StatMess
MessageFrm.StatusMessage(Msgtxt)
Try
' Reset the cursor to the hourglass postion.
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
SQLConnection(loginDatabase, loginIPaddress, "Standard",
loginuser, loginpass)
Dim MyCmd2 As New SqlCommand(SQLquery)
MyCmd2.CommandTimeout = 600
MyCmd2.Connection = SQLConn
SQLConn.Open()
MyCmd2.ExecuteNonQuery()
SQLConn.Close()
Application.DoEvents()
Catch ex As System.Data.SqlClient.SqlException
result = "There was an SqlException.." & vbCrLf & "Details..." &
vbCrLf & ex.ToString()
Catch ex As InvalidCastException
result = "There was an InvalidCastException..." & vbCrLf &
"Details..." & vbCrLf & ex.ToString()
Catch ex As Exception
result = "There was an Unhandled Exception..." & vbCrLf &
"Details..." & vbCrLf & ex.ToString()
Finally
If IsNothing(MessageFrm) = False Then MessageFrm.Dispose()
If IsNothing(SQLConn) = False Then
If SQLConn.State <> Data.ConnectionState.Closed Then
SQLConn.Close() : SQLConn.Dispose()
End If
MsgBox(result)
Cursor.Current = System.Windows.Forms.Cursors.Default
MessageFrm.close()
End Try
' Reset the cursor to the default for all controls.
Cursor.Current = System.Windows.Forms.Cursors.Default
SQLConn.Close()
MessageFrm.close()
End Function
thanks
Gerry