vb.netms-accessexceptionaceoledb

System.AccessViolationException occurs with MS Access databases just over WiFi connection


I'm developing a desktop application for my company (it's just a prototype, actually) for bringing simple services to production department (tool and process instructions, presence records, product traceability, etc). I'm using VB.net and wpf; some MS Access databases are the backend. It uses Access Database Engine 2016.

I have a simple function used to update database records, here's it:

  Public Function UpdateDatabaseRecord(DatabaseNumber As Integer, tblName As String, SearchInColumn As String, SearchBy As String, UpdateColumn As String, UpdateTo As String) As Integer
    Try
        Using ServerConnection As New OleDbConnection(ConnectionSelector(DatabaseNumber))
            Dim CommandString As String
            If SearchInColumn <> "ID" Then
                CommandString = "UPDATE [" & tblName & "] SET [" & UpdateColumn & "]=@UpdateColumn WHERE [" & SearchInColumn & "] = " & DQ & SearchBy & DQ
            Else
                CommandString = "UPDATE [" & tblName & "] SET [" & UpdateColumn & "]=@UpdateColumn WHERE [" & SearchInColumn & "] = " & SearchBy
            End If
            Dim CommandUpdate As New OleDbCommand(CommandString, ServerConnection) With {.CommandTimeout = 10000}
            With CommandUpdate.Parameters
                .AddWithValue("@UpdateColumn", UpdateTo)
            End With
            ServerConnection.Open()
            CommandUpdate.ExecuteNonQuery()
            ServerConnection.Close()
        End Using
        UpdateDatabaseRecord = 0
        SetCentralTimeStamp(DatabaseNumber, tblName)
    Catch ex As Exception
        Msg(Reflection.MethodBase.GetCurrentMethod.Name & NewLine & ex.Message & NewLine & "Err. Number " & Err.Number, "Database Error", MessageBoxButton.OK, MessageBoxImage.Error)
        UpdateDatabaseRecord = Err.Number
    End Try
End Function

Sometimes the application uses this function in the main thread; sometimes it runs it from scheduled task (clocked by a forms.timer every two minutes). This tasks aren't obviously in the main thread, but the code has been used succesfully for a couple of months with computers directly connected to company network via LAN cable. Recently I tried my application on a laptop connected via wifi to the company network, and I get an exception that's crashing my app. I installed VS on that laptop to debug the code, and I found that an AccessViolationException is raised on line "CommandUpdate.ExecuteNonQuery". I tried to google it but it seems that this exception shouldn't be raised from managed code. The error occours only with laptop connected via wifi. Also, another function reads data from the databases: sometimes I get the same error in it, in the line where the connection is being opened (connection.open).

What should I check?

Thanks in advance.

ps "ConnectionSelector" is a simple function which returns the appropriate ConnectionString based on database number.

EDIT 1 - The WiFi network is created plugging directly a LAN cable from the actual wired network, using a common wireless router. IP addresses are automatically assigned and the connection works, since the app is able to get data from databases.


Solution

  • I solved the problem myself and I'm posting here the solution I found: I hope it will help someone in the future.

    I resolved simply enabling all OLEDB Services for the database connection. It looks like connection pooling really help stability and performance, especially when using a wifi network like I'm forced to do. If you want, Google "OLEDB Services" and look for enabling them all.