I need to perform a Compact and Repair operation on an Access database. In order to do that, all open connections to the database need to be closed. Unfortunately there are open connections that I can't always necessarily trace down and close properly. Is there a way to disconnect all open connections through code?
This may be of interest: http://www.tek-tips.com/viewthread.cfm?qid=79802
There is nothing particular about an access file say as compared to a text file, or a simple power point file sitting on the disk. We are talking about a plane jane windows file here.
So, your real question is can you disconnect a process that has a word file open or any old file that just happens to be sitting on the hard drive?
You might be able to kill the process and connection, but then again you would not be able to ensure that pending data writes to that word file (or access mdb file) would occur.
So, to my knowledge, even if you could determine what process has that power-point file open, I don't think you can reliable kill that process and close that connect to the file that is open and be sure that pending data to be written will in fact get written. You can't know what that code and process has pending in terms of updates waiting to be written to disk.
While failure write out pending data in a power point file might not be such a big deal, but in the case of data, you asking for real trouble.
The only real approach here is a graceful and proper shut down of the application/process that has that windows file open.
About all your code can attempt is to gain exclusive use of the file, and if you can't do that, then you have to inform the user that a compact is not possible until such time as exclusive use of the file can be obtained.
You can certainly open up the admin tools on the computer, and check the users who have the file open, but killing those user connections is done at your own risk.