0

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.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
IFrank
  • 419
  • 1
  • 5
  • 12
  • Sounds like it's a network infrastructure issue to me if it works flawlessly when hard wired. Is the wifi actually on the same network as cable connections? Are the ip ranges the same? – Hursey Aug 31 '20 at 20:51
  • 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. Is there any settings I should check from the wireless router? Can it be a pooling issue? – IFrank Aug 31 '20 at 21:16
  • 1
    Your connection is ultimately resolved to a FILE OPEN commend. This is in effect NOT a tc/ip socket connection, but that of KEEPING a file open over a network. If that connection has one tiny hiccup? then the file handle is LOST and thus so is a reliable connection to the database. It can cause corruptions during updates. This is much like a star trek transporter fail and if the data stream is cut or damaged during a transport, then the molecules of the person can't be re-assembled on the other side, or in this case your file state and buffers are lost. Sql express for wifi is good idea. – Albert D. Kallal Sep 01 '20 at 02:29

1 Answers1

0

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.

IFrank
  • 419
  • 1
  • 5
  • 12