0

I am pulling my hair out trying to work out an error I'm having with my application. Basically I am getting random errors when trying to populate a dataset from an SQLite query. I can deal with the fact that it might not always return results from the SQLite DB because the tables may be locked, etc. but my code keeps failing and I'm unable to trap the error:

My code looks like this:

            Dim ExQry As New SQLiteCommand(QryString, SQLConnect)
            ExQry.CommandType = CommandType.Text

            Dim da As New SQLiteDataAdapter(ExQry)
            dasSpice.Clear()

            Try
                da.Fill(dasSpice, "Calls") 'Error occurs on this line
            Catch ex As SQLiteException

Basically what happens is my code will get to the da.fill(dasSpice, "Calls") statement and throw an error:

A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in System.Data.SQLite.dll

However, this error is not caught in the catch statement, but instead my code will skip directly to the cell_formatting event and try to populate my gridview with empty data. Part of my form_load event is to go off and populate the dasSpice dataset and then return to populate another dataset and finally update the gridview. However, because it bombs out on the dasSpice dataset it never returns to populate the second dataset and hence gives me an empty gridview.

Is there anyway at all I can catch this error, or allow my code to return to the form_load event to continue on with the rest of the code? I can provide more detail if required.

Any help would be greatly appreciated as I'm totally at a loss with this. Thanks

Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
Riples
  • 1,167
  • 2
  • 21
  • 54

2 Answers2

0

You are catching a SqlLiteException by the exception raised is an SEHException.

Try this:

Catch ex As Exception

  If TypeOf ex Is SQLiteException Then
    ..  ... blah
  Else
    ' ... not a SQLiteException so do something else...
  End if

Then in .... bits look inside the exception to see what info you can find. How should you diagnose the error SEHException - External component has thrown an exception

Also what is in your query?

Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • Thanks for the reply. As the code doesn't always fall over I will try that and see what happens. I did have ex as exception previously and never caught anything, but I will structure it like you have mentioned. Also, for my query it is a very basic Query string: QryString = "SELECT id, summary, status, c_location, c_store_device FROM tickets WHERE status = 'open' AND c_location = '" & tmpID & "'" – Riples Sep 17 '13 at 08:26
  • Okay, tested the exception code above and managed to make my code fail again but the exception wasn't picked up and I just got a blank datagridview again. – Riples Sep 17 '13 at 08:31
0

You must catch correctly exceptions or base classes from them:

Try
   ...
Catch ex As SQLiteException 'will handle all SQLiteException (and subclasses not explicitly specified)
   ...
Catch ex As System.Runtime.InteropServices.SEHException 'Catch all SEHException
   ...
Catch ex As ... 'Catch another exception
   ...
Catch ex As Exception 'Catch all remaining exceptions.
   ...
End Try

See Try/Catch blocks.

LS_ᴅᴇᴠ
  • 10,823
  • 1
  • 23
  • 46