Unlocking MS Access MDB Files

As a ColdFusion newbie about a year ago, I can distinctly recall the frustration of dealing with Microsoft Access database files which had been "locked" by the ColdFusion Application Server accessing them. I can remember being unable to delete or overwrite older database files, and trying stupid workarounds like uploading newly named databases (and having to change the resulting ODBC System DSN).

The solution is incredibly simple, as will be this article. The trick to unlocking the hold on the MDB file is to simply throw it a query that will cause an error. The easiest way to do that is to attempt a select from a table that doesn't exist. Code like this should do the trick (unless you're really strange and actually have a table named "whereveryoucanfindthem" and a field named "cutemeerkats"). ;)

<cfquery name="unlockmdb" datasource="dbnamegoeshere">
  SELECT cutemeerkats
  FROM whereveryoucanfindthem
</cfquery>

Place this snippet into a file (I call mine die.cfm), and then run it whenever you need to unlock the database. It could even be extended to accept a datasource name via the query string and unlock any database on your machine, but I'll leave that to anyone who wants to try it as an experiment (my goal here is for simplicity).

Hopefully anyone new to CF and databases who has struggled with this issue in the past will have to suffer no longer. I encourage anyone with questions or information relevant to this article to comment below. If you've got alternate solutions or warnings, be sure to pass them on.

isaac

Comments

Very interesting... I am going to make die.cfm now and put it in my link bar. I have previously just killed cfserver.exe and restarted it if it is on a local box, but this is way easier.

If I understand the problem right, it sounds like what you really want to do is go into the CF Administrator and open up the datasource for your application. Once you're in there, deselect the box so that the CF app server will not keep a constant connection. Once you do this, it won't constantly keep the database locked up. Like I said, I'm not sure about exactly what the circumstances are when you're having the trouble with the access database remaining locked. But if I do understand it, I would imagine this solution is better than sending the database a bad SQL statement.

I think this is a performance issue. In general, you should keep the db connection turned on if the site is live. If your playing around on a test server, then yes, it's best to turn off that option.

IT IS THE solution i was looking for!

I am a webmaster for a website. As I use the Access database i the main page, it was impossible to be to make changes in the database as it was always locked. I was waiting all the time to see when it would unlocked. I searched in Google about unlocking the access DB and it got me to this page. It was the ultimate solution for my problem. Who invented it?? I am grateful to him. Hope this forum helps me in fixing a lot of such problems. Prem

"invented" ?

I don't think this was invented per se, it's just how Access is unlocked, or can be. Again, the best option is to turn off the maintain db thing, since, in theory, you should NOT be changing your DB while your site is live. Of course, we all know how far theory is from reality. ;)

I HOPE IT IS THE SOLUTION I'VE BEEN LOKING FOR

I DONT KNOW WHAT A COLD FUSION SERVER IS, WILL THIS WORK FOR MY SHARED FILE APPLICATION ON ACCESS97. I WROTE IT FOR A GROUP OF PEOPLE AT WORK, AND I HAVE TROUBLE UPDATING IT, BECAUSE PEOPLE ARE IN IT (LOCKED). THE LOGIC I WROTE TO KICK PEOPLE OUT WITH TIMERS ON HIDDEN FORMS SEEMS DEFEATED WHEN THEY DONT HAVE IT CURRENT ON THERE DESKTOP (MINIMIZED, I GUESS). I'LL TRY THIS BUT IM OPEN TO CLEARIFICATIONS ON MY PROBLEM. iVE ALSO HEARD OF SOME CODING THAT GOES INTO EFFECT WHEN THE FORM IS NOT ACTIVE OR NOT ON DESKTOP, BUT I DONT KNOW THE RIGHT VB CODE.

this sound good but confusing

Can you please explain in simpler formI am a mother of 5 and my brain is fried but would love to try this on a file i would like to use for home billing business. Thanks you

Guru

I am a newbie in this MS Access DB. I've tried to understand and crack this thing for the last few wks unsuccessful. Plzzzzzzzzzzz help. http://www.mortgagecoach.com/download/432/mtgcoach432c.exe Your expertice and advice will greatly be appreciated,

Any Other Workaround

I have tried your suggestion, but it has failed to unlock database on servers where my sites are hosted, this is quite aggrevating when I need to get work done, and have to wait sometimes up to an hour for the locked database to be released. Any ideas would be greatly appreciated. Thanks in advance.

A Brilliant Fix

This message may show up twice, but it appears that my first message may have been accidental spam, probably because I listed the website that I implemented this fix on. Anyway, just wanted to say that operation killdb.cfm (a.k.a. die.cfm) is in full effect at [my site] and is working great! It is simple, and works perfectly for the stubborn .ldb problem in MS Access. Thanks for the fix, I am now a member of this site because of it! Cheers!

Cannot delete the LDB

I created an access in access2003 , its being used in multiuser environment ..based on a particular value the database is automatically closed and only i can change the value. Even after the database is closed the .ldb file exist .. Now I tried your code die.cfm , not very sure how to use it , because with the .cfm extension its not getting executed , can you suggest how can i get it executed ?, Or should I create a false query within the database so that it throws the error , but then while running the query I have to login to the database that will create the lock file .. The os used is Win Xp and the file is placed on a common shared drive. suman sengupta

cannot delete the laccdb

I have a lock on our MSA 2007 database, no one is actually logged in but the registry did not clear in the iaccdb lock file so it constantly remains in a locked status. I can't use the above formula as I am not directly running cfm, so can someone help me with a workaround?, can I set up a msaquery inside the database that will unlock users. Tel

How to, just using MS Access

Open the Access locked database, Make a new query but don't select any tables. Go to SQL view Type: select a from b; Run with the ! It gives an error because you have no table called 'b' You can save the query which tells you the MDB is no longer locked. Close the database and it is unlocked! There is no LDB