Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disconnect All Open Connections to MS Access Database

Tags:

c#

ms-access

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?

like image 523
Blake Blackwell Avatar asked Jul 19 '10 17:07

Blake Blackwell


1 Answers

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.

like image 99
Albert D. Kallal Avatar answered Oct 15 '22 11:10

Albert D. Kallal