Help - GetOleDbSchemaTable is crashing. RRS feed

  • Question

  • User186656733 posted

    I am trying to find if a table exists in an Access database using this code:

    myDataTable = oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})

    The idea is to cycle through the resulting data table and find if the one I want is there.

    However, the above statement is CRASHING with this error:

    System.AccessViolationException was unhandled

    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    This was working a few days ago.  What am I missing?

    Help most appreciated.

    Wednesday, March 26, 2014 12:30 AM


All replies

  • User-1199946673 posted

    I always use the GetSchema method. Instead of looping through all the tables, you better set the restriction on only the table you're looking for. If it returns 1 row, the table exists, if it doesn't return a row,. the table doesn't exist.

        Dim restrictions(3) As String
        restrictions(2) = "your tablename"
        Dim myDataTable As DataTable =  oleConn.GetSchema("Tables", restrictions)
        If myDataTable.Rows.Count = 1 Then
            'Table exists
            'Table does not exist
        End If


    This was working a few days ago.  What am I missing?

    Most likely, your database is corrupt. This is ussualy caused when you don't close and dispcose the connection properly.In order to prevent this, you better use the 'using ... end using' pattern. Code examples:


    To Repair the database, use Access (Compact and repair), or you can do this in code:


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 26, 2014 4:57 AM
  • User186656733 posted

    This was helpful since I have been looking for a long time for a way to narrow the results.

    I found out the crash was due to a corrupt database!

    I wish error messages would be more helpful...

    Thank you for your help.

    Wednesday, March 26, 2014 10:03 AM