troubleshooting Question

Recover from SQL Exception in Try Catch block

Avatar of Bruce
BruceFlag for United States of America asked on
.NET Programming
3 Comments1 Solution280 ViewsLast Modified:
How do I continue execution after a primary key violation exception is returned?

I am executing multiple inserts and if an exception is returned I want to continue with the next insert.

Sub DoMyInsert()
  'Setup Local Variables
  Try

    For Each oRow as DataRow In datTable.Rows

      'If a primary key exception occurs, how do I jump back into this loop?

      'Get data
      'Insert into another table

    Next

  Catch ex As SqlException
    'Do I do something here?
  Catch ex As Exception
    Throw ex
  Finally
    m.Dispose()
  End Try
End Sub

Do I need to user a couter loop and hold the index and return?

Do I need to user and "On Error...Resume Next" block?

TIA,
Bruce

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros