0

I use MS Access to a desktop application. Users might not have access or office installed.Is it possible to compact a MS access using a SQL query?

Does after insertions and deletions without compacting the database the size continuously increasing? If yes, when it will exceeds its maximum allowed size, even though it does not have many records, it will deny any further insertions?

Reven
  • 609
  • 3
  • 9
  • 17
  • How are you connecting to the database from your application? – Rowland Shaw Dec 10 '14 at 10:57
  • using OLEDB connection – Reven Dec 10 '14 at 11:01
  • without access or access db engine installed it is not possible to connect to the DB at all. Tipp: http://stackoverflow.com/help/how-to-ask – Krish Dec 10 '14 at 13:40
  • @krishKM not true if you are accessing `mdb` files since Windows has had the necessary drivers for them wince Win95. The ACE drivers (or a full/runtime installation of Access) are only necessary if you are using the `accdb` format introduced from Access 2007). – Renaud Bompuis Dec 11 '14 at 01:57

1 Answers1

2

You are right that a MSAccess database (like most databases) will increase in size as you add/delete/update its records.
Compacting your Access database on a regular basis is a highly recommended maintenance activity since it will optimise and repair any recent damages without them having a chance to compound and make things worse.

Ideally, you want to do this on a schedule, as part of your datbaase backup strategy for instance (every night is a good idea).

As for your other question: you cannot just issue a SQL command to compact an Access database.

However, you can compact a database from code using the DAO library that is already installed on every Windows machine.

Have a look at the solutions presented in question Access “Compact and Repair” programatically

One word of advice though: do not attempt to compact a shared database on the network unless you are absolutely sure you are the only one accessing it. You could corrupt the database.
At any rate, I would strongly recommend that you first make a copy of the database before doing any compact/repair action on it.

Community
  • 1
  • 1
Renaud Bompuis
  • 16,596
  • 4
  • 56
  • 86