I have been reading thru a lot of different options for compacting and repairing an access database, but most require the user to have Access installed. Is there any code avaialble that would allow this to occur, without the user having access installed?
I have "Microsoft.ACE.OLEDB.12.0" being used as part of my connection string to the database.
Thanks for any assistance.

Jayraj ChhayaRank #304 · 8.2K reputationPosted Apr 25, 2024, 1:59 AM EDT
To compact and repair an Access database without the need for Access to be installed, you can achieve this programmatically using C# in a .NET environment. You can utilize the
Jet.OLEDB.4.0provider to compact and repair the database. Here is a sample code snippet to accomplish this:using System.Data.OleDb; class Program { static void Main() { string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\path\\to\\your\\database.accdb;"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = connection; cmd.CommandText = "COMPACT DATABASE 'C:\\path\\to\\your\\database.accdb'"; cmd.ExecuteNonQuery(); } } }By using the
COMPACT DATABASEcommand with theJet.OLEDB.4.0provider, you can compact and repair the Access database programmatically without the need for Access to be installed on the user's machine.RICHARD KNOX100 reputationPosted Apr 25, 2024, 10:08 PM EDT
I tried your code, but I got this as an error.