Results 1 to 2 of 2

Thread: LBD Lock File Remains After Connection Closed

  1. #1

    Thread Starter
    Join Date
    Jun 2007

    LBD Lock File Remains After Connection Closed

    I'm using MDB database files and I've noticed that if I run many different SQL statements during a single connection, the LDB file doesn't get deleted when the connection is closed. When the program is closed, the LDB file is then deleted.

    I've made a simple program to illustrate this problem, this is a bit of a pointless program, but it shows the problem:

            Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=test.mdb")
            'changing this loop to something higher (such as 100) causes the problem
            For counter As Integer = 0 To 10
                    Dim query As String = "SELECT * FROM MyTable"
                    Dim cmd As OleDbCommand = New OleDbCommand(query, con)
                    Dim dr As OleDbDataReader = cmd.ExecuteReader
    I have a loop setup in the above that just repeatedly does the same thing 10 times. Running this loop, the LDB file doesn't remain at the end of the routine. If I change the loop to run 100 times, the LDB file will remain until I close the program.

    I suspect that when the program calls con.close(), the MDB file is still being used to so the LDB file isn't deleted. That's just my best guess though. Not sure how to fix that.

    Anyone know the cause of this and a possible solution?
    Last edited by peternm22; Aug 17th, 2019 at 06:27 PM.

  2. #2

    Thread Starter
    Join Date
    Jun 2007

    Re: LBD Lock File Remains After Connection Closed

    Alright, after a lot of trial and error I finally figured out what I was doing wrong in the above example. I needed to call dr.close(). After adding that, I'm not having any problems. I even increased the loop to 1,000,000 to test. It took a little while to run, but the ldb file was successfully deleted at the end.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width