Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. MS Access database not closing

MS Access database not closing

Scheduled Pinned Locked Moved Visual Basic
databasetestingbeta-testingtutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Charles Wolfe
    wrote on last edited by
    #1

    I have a VB application that updates one database using input from another database. The code looks like: Dim InputDC as OldDatabaseConnection Dim OutputDC As ... InputDC.Open OutputDC.Open For each table in Input Database Read data from old table Copy data to new table Write new table to Output database ... InputDC.Close OutputDC.Close Sometimes [often] the Output database does not close, that is the Output.ldb file is left hanging around for an indefinite time period. Sometimes the program runs fine e.g. 50 times in a row; then suddenly it will hang. I've been programming for 45 years and have done consulting and know the first rule is that "Users lie about no changes"; however in this case there ARE no changes to the code. The program wants to rename the data bases so that Input.mdb becomes Input_Old.mdb and Output.mdb becomes Input.mdb. With the control file (Output.ldb) hanging around, the Rename causes an exception. It is [almost] always the Output.ldb file that is still around implying that Output.MDB is still open... I have taken the code apart line by line; there is only one open and close per database. There are closes within Catch paragraphs. But, there is only one .Open per database. I've tried a variety of loops testing for the .ldb to go away, but this usually just results in the program running for a very long time doing nothing. When the program is terminated thru its main form's Exit button, the .ldb files go away almost immediately. I can watch the history of file creation, etc. in Windows Explorer as the program runs. Has anyone experienced this "feature"? If so have you figured out how to solve it?

    Charles Wolfe C. Wolfe Software Engineering

    D L M 3 Replies Last reply
    0
    • C Charles Wolfe

      I have a VB application that updates one database using input from another database. The code looks like: Dim InputDC as OldDatabaseConnection Dim OutputDC As ... InputDC.Open OutputDC.Open For each table in Input Database Read data from old table Copy data to new table Write new table to Output database ... InputDC.Close OutputDC.Close Sometimes [often] the Output database does not close, that is the Output.ldb file is left hanging around for an indefinite time period. Sometimes the program runs fine e.g. 50 times in a row; then suddenly it will hang. I've been programming for 45 years and have done consulting and know the first rule is that "Users lie about no changes"; however in this case there ARE no changes to the code. The program wants to rename the data bases so that Input.mdb becomes Input_Old.mdb and Output.mdb becomes Input.mdb. With the control file (Output.ldb) hanging around, the Rename causes an exception. It is [almost] always the Output.ldb file that is still around implying that Output.MDB is still open... I have taken the code apart line by line; there is only one open and close per database. There are closes within Catch paragraphs. But, there is only one .Open per database. I've tried a variety of loops testing for the .ldb to go away, but this usually just results in the program running for a very long time doing nothing. When the program is terminated thru its main form's Exit button, the .ldb files go away almost immediately. I can watch the history of file creation, etc. in Windows Explorer as the program runs. Has anyone experienced this "feature"? If so have you figured out how to solve it?

      Charles Wolfe C. Wolfe Software Engineering

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      I've seen this a few times before with other files on windows system. (Windows Server 2003) If I had to guess, the OS is doing some caching or something and the operation is not finished. My solution to this was to use a Try-Catch block and sleep for a few seconds before trying to access the file again. I put a counter in the loop so that if it tries more than 100 times, it finally aborts the operation. Not the best solution, but at least my program no longer crashes because Windows didn't finish renaming the file. I'm an old VAX/VMS guy and the crap you have to deal with Windows is just awful. (getting off my soapbox now ...) ;) Give the Try-catch loop thing a try and see if it works for you.

      1 Reply Last reply
      0
      • C Charles Wolfe

        I have a VB application that updates one database using input from another database. The code looks like: Dim InputDC as OldDatabaseConnection Dim OutputDC As ... InputDC.Open OutputDC.Open For each table in Input Database Read data from old table Copy data to new table Write new table to Output database ... InputDC.Close OutputDC.Close Sometimes [often] the Output database does not close, that is the Output.ldb file is left hanging around for an indefinite time period. Sometimes the program runs fine e.g. 50 times in a row; then suddenly it will hang. I've been programming for 45 years and have done consulting and know the first rule is that "Users lie about no changes"; however in this case there ARE no changes to the code. The program wants to rename the data bases so that Input.mdb becomes Input_Old.mdb and Output.mdb becomes Input.mdb. With the control file (Output.ldb) hanging around, the Rename causes an exception. It is [almost] always the Output.ldb file that is still around implying that Output.MDB is still open... I have taken the code apart line by line; there is only one open and close per database. There are closes within Catch paragraphs. But, there is only one .Open per database. I've tried a variety of loops testing for the .ldb to go away, but this usually just results in the program running for a very long time doing nothing. When the program is terminated thru its main form's Exit button, the .ldb files go away almost immediately. I can watch the history of file creation, etc. in Windows Explorer as the program runs. Has anyone experienced this "feature"? If so have you figured out how to solve it?

        Charles Wolfe C. Wolfe Software Engineering

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Maybe, just maybe, your newly created/modified file is in use by another program, e.g. an anti-virus or an indexer (such as Google Desktop Search). What you could do is provide a loop that tries 5 times, with 1 second interval. It is what Windows Explorer does when you tell it to delete a file! :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        1 Reply Last reply
        0
        • C Charles Wolfe

          I have a VB application that updates one database using input from another database. The code looks like: Dim InputDC as OldDatabaseConnection Dim OutputDC As ... InputDC.Open OutputDC.Open For each table in Input Database Read data from old table Copy data to new table Write new table to Output database ... InputDC.Close OutputDC.Close Sometimes [often] the Output database does not close, that is the Output.ldb file is left hanging around for an indefinite time period. Sometimes the program runs fine e.g. 50 times in a row; then suddenly it will hang. I've been programming for 45 years and have done consulting and know the first rule is that "Users lie about no changes"; however in this case there ARE no changes to the code. The program wants to rename the data bases so that Input.mdb becomes Input_Old.mdb and Output.mdb becomes Input.mdb. With the control file (Output.ldb) hanging around, the Rename causes an exception. It is [almost] always the Output.ldb file that is still around implying that Output.MDB is still open... I have taken the code apart line by line; there is only one open and close per database. There are closes within Catch paragraphs. But, there is only one .Open per database. I've tried a variety of loops testing for the .ldb to go away, but this usually just results in the program running for a very long time doing nothing. When the program is terminated thru its main form's Exit button, the .ldb files go away almost immediately. I can watch the history of file creation, etc. in Windows Explorer as the program runs. Has anyone experienced this "feature"? If so have you figured out how to solve it?

          Charles Wolfe C. Wolfe Software Engineering

          M Offline
          M Offline
          Member 1957436
          wrote on last edited by
          #4

          Hello I had a very similar problem with an Access database not closing in a VB.NET application. I tried various things like waiting for 5 seconds, a loop retrying every few seconds, adding "OLE DB Services=-4" to the connection string. Nothing worked reliably until I added these two lines after all the database close statements:

          GC.Collect()
          GC.WaitForPendingFinalizers()

          I hope this helps. Marek

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups