J
Jason MacKenzie
We have a class that does a lot of our data access like returning datasets
etc. Occasionally the error handling will send an email saying : Exception
has been thrown by the target of an invocation.
But if I step through the code and paste the offending SQL statement into
Enterprise Manager it will give me the actual error. Has anyone else
experienced this?
I should point out that 95% of the time I will be emailed the correct error
returned by SQL Server. Here is the code:
Public Function ReturnDataSet(ByVal SQLStatement As String, ByVal
InsertRowAtIndex0 As Boolean) As DataSet
dim myConnection as New OdbcConnection(strConnectionString)
dim myCommnand New OdbcCommand(SQLStatement, myConnection)
dim myDA asNew OdbcDataAdapter
myDA.SelectCommand = myCommand
Dim myDS As New DataSet
Try
m_GeneralError = ""
myDA.Fill(myDS)
If InsertRowAtIndex0 Then
Dim BlankRow As System.Data.DataRow =
myDS.Tables(0).NewRow()
myDS.Tables(0).Rows.InsertAt(BlankRow, 0)
End If
Return myDS
Catch ODBCError As OdbcException
m_GeneralError = "The following error occurred and has been
reported to IS: " & ODBCError.Message
Me.MailError(ODBCError.Message, strApplicationName &
"@formet.com", "Error with " & strApplicationName)
Catch eEx As Exception
m_GeneralError = "The following error occurred and has been
reported to IS: " & eEx.Message
Me.MailError(eEx.Message, strApplicationName &
"@formet.com", "Error with " & strApplicationName)
Finally
myDS.Dispose()
myDA.Dispose()
If myConnection.State = ConnectionState.Open Then
myConnection.Close()
End If
myConnection.Dispose()
myConnection.Dispose()
myCommand.Dispose()
End Try
End Function
etc. Occasionally the error handling will send an email saying : Exception
has been thrown by the target of an invocation.
But if I step through the code and paste the offending SQL statement into
Enterprise Manager it will give me the actual error. Has anyone else
experienced this?
I should point out that 95% of the time I will be emailed the correct error
returned by SQL Server. Here is the code:
Public Function ReturnDataSet(ByVal SQLStatement As String, ByVal
InsertRowAtIndex0 As Boolean) As DataSet
dim myConnection as New OdbcConnection(strConnectionString)
dim myCommnand New OdbcCommand(SQLStatement, myConnection)
dim myDA asNew OdbcDataAdapter
myDA.SelectCommand = myCommand
Dim myDS As New DataSet
Try
m_GeneralError = ""
myDA.Fill(myDS)
If InsertRowAtIndex0 Then
Dim BlankRow As System.Data.DataRow =
myDS.Tables(0).NewRow()
myDS.Tables(0).Rows.InsertAt(BlankRow, 0)
End If
Return myDS
Catch ODBCError As OdbcException
m_GeneralError = "The following error occurred and has been
reported to IS: " & ODBCError.Message
Me.MailError(ODBCError.Message, strApplicationName &
"@formet.com", "Error with " & strApplicationName)
Catch eEx As Exception
m_GeneralError = "The following error occurred and has been
reported to IS: " & eEx.Message
Me.MailError(eEx.Message, strApplicationName &
"@formet.com", "Error with " & strApplicationName)
Finally
myDS.Dispose()
myDA.Dispose()
If myConnection.State = ConnectionState.Open Then
myConnection.Close()
End If
myConnection.Dispose()
myConnection.Dispose()
myCommand.Dispose()
End Try
End Function