Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

Last post 07-17-2008 2:52 AM by Scarlet_Spidy. 5 replies.

Sort Posts:

  • Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

    07-03-2008, 12:59 AM

    Hi, I have a very regular problem with MS Access showing random results when being written to from Visual Studio 2008.  It happens on all computers including the development machine, using Vista or XP, VS 2005 or VS 2008.

    Is there a VB.Net flush command I can use before reading the data ?.

    I write data to a table and then immediately go to read that data.

    I can make it work if I wait up to 3 seconds before I read the data after a write, using a sleep command. Unfortunately 3 seconds is way too long.

    Are there any known problems with writing data to MSAccess 2003 from .Net, using VS 2008, VB.

    Another weird things that happens is that only half the data is there if I write to an Access table and then go to read it immediately. Sometimes the data's there, sometimes not, with the exact same code and data. Sometimes the whole table fills with the data from the first record. This is happening throughout my code. Anywhere there's data being written to Access there's a problem if I go to read it immediately after.

    Sometimes the Access table is blank, even though data has been written to it, and then on a second run of the exact same code it comes good, or gets half the data or every record is a duplicate of the first record. 

    The code is good, so it's not a coding problem, and I can run the exact same code and get good results. So it's definitely an intermittent problem.

    I appreciate any help I can get with this.

    I run all my access writes through the same code. The part of the code that writes the data is "command1.ExecuteNonQuery()". Whether I read the data from a datatable or as a merged word document, I still get the same problems. So I'm guessing that there's a problem with writing the data.

     

        Public Sub ExecuteCommand(ByVal DataTableName As String, ByVal sqlString As String, ByRef LocalSQL As LocalSQL)
            Try
                Do Until SQLprocessingLocal = False
                    System.Windows.Forms.Application.DoEvents()
                Loop
                SQLprocessingLocal = True
                dt = New DataTable
                Dim command1 As OleDb.OleDbCommand = New OleDb.OleDbCommand(sqlString, oConnLocal)
                adapter1 = New OleDbDataAdapter(command1)
                Select Case DataTableName
                    Case "dtLocalPayments"
                        dtLocalPayments = New DataTable
                        adapter1.Fill(dtLocalPayments)
                    Case "dtTemp"
                        dtTemp = New DataTable
                        adapter1.Fill(dtTemp)
                    Case "dtDGV"
                        dtDGV = New DataTable
                        adapter1.Fill(dtDGV)
                    Case Else
                        Try
                            command1.ExecuteNonQuery()
                        Catch ex As OleDb.OleDbException
                            MessageBox.Show(ex.Message, "OleDbException")
                            SQLprocessingLocal = False
                            Exit Sub
                        Catch ex As Exception
                            MessageBox.Show(ex.Message, "GeneralException")
                            SQLprocessingLocal = False
                            Exit Sub
                        End Try
                End Select

            Catch ex As Exception
                MsgBox("Error when doing an ExecuteCommand, call Tech Support")
                SQLprocessingLocal = False
            End Try
            Debug.Print(sqlString)
            SQLprocessingLocal = False
        End Sub



     

  • Re: Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

    07-03-2008, 2:28 AM

    I've never had a problem like this with Access, but then I have never used Windows Forms.  Perhaps you should ask your question in a forum to do with Windows Forms rather than ASP.NET: http://.windowsclient.net/forums

    By the way, at first glance, it only looks like you are writing to Access if the Case is Else. In all other cases, you are merely populating a DataTable.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

    07-03-2008, 3:04 AM

    Yes, it's only writing to access in the else statement. I noticed a similar question in this forum so I thought it would be a suitable place to post the question, but thanks for the suggestion. I might consider that if I don't get any results here.

  • Re: Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

    07-03-2008, 3:21 AM

    If latency is the cause, it could well be a problem with the network.  Since there is no "network" to speak of in ASP.NET, I really do think that your question is better placed elsewhere.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

    07-03-2008, 6:32 PM

    OK, I'll start looking elsewhere and if I find an answer elsewhere I'll post the data here. Also, it can't be a network problem because the code and the Access database are on the same computer.

    The problem seem to be that .net and Access don't talk too well to each other. 

  • Re: Intermittent Data Insert and Read with MS Access with .Net, latency or flushing problem

    07-17-2008, 2:52 AM
    Answer

    The way I got around things was to make sure the same adapter was being used for all commands and using transactions. Doing a final read before opening the document via word (with merge fields to access).  Apparently the Jet (MS Access) database engine wasn't built to manage these sorts of things. In any case, I updated all code to ado.net from ado and things seem to be improved, although still not perfect. For some reason using dataviews and datarows with updates instead of sql inserts and updates seems to improve things a bit as well. No perfect answers here, but a lot of ideas to make things more liveable.

Page 1 of 1 (6 items)
Microsoft Communities
Page view counter