PHV,
Below is the example of my attempt to catch the exception. It does work and I hate it: it contains GoTo and interrogates message and not the code. I have no clue what substitutes On Error Resume Next and Err.Clear in VB.NET.
Private Sub DropTempTables()
Dim objCmd As New OleDb.OleDbCommand
Dim strSQL As String
Dim intTerr As Integer
Dim intTerrCount As Integer
Dim dctTerrToSkip As New ListDictionary
DropItAgain:
Try
OpenDB()
intTerrCount = mobjState.Territories.Count
objCmd = New OleDb.OleDbCommand(strSQL, mobjConn)
objCmd.CommandType = CommandType.Text
For intTerr = 1 To intTerrCount
If Not dctTerrToSkip.Contains(intTerr) Then
strSQL = "DROP TABLE TEMP_" & CStr(intTerr) & ";"
objCmd.CommandText = strSQL
objCmd.ExecuteNonQuery()
End If
Next intTerr
Catch ex As Exception
If InStr(ex.Message, "does not exist", CompareMethod.Binary) > 0 Then
If Not dctTerrToSkip.Contains(intTerr) Then
dctTerrToSkip.Add(intTerr, intTerr)
End If
GoTo DropItAgain
Else
MessageBox.Show(ex.Message & vbCr & ex.TargetSite.Name, "Cannot drop Temp table.", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Finally
CloseDB()
objCmd = Nothing
End Try
vladk