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"). ;)

SELECT cutemeerkats

FROM whereveryoucanfindthem

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