Exception has been thrown by the target of an invocation

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
 
W

William \(Bill\) Vaughn

Why are you using the Odbc .NET Data Provider instead of SqlClient? It has
far richer (and more SQL Server-specific) exception handlers.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
J

Jason MacKenzie

Its not my choice, unfortunately.


William (Bill) Vaughn said:
Why are you using the Odbc .NET Data Provider instead of SqlClient? It has
far richer (and more SQL Server-specific) exception handlers.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top