0

Now i have database already in my folder but size of file is biggest.Then i want to compact this file but i get some error about "Invalid argument.", How can i do in this case. thank u

this my code

Dim JRO As New JRO.JetEngine
    Dim source = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory & "Code7.accdb"
    Dim compact = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory & "newCode7.accdb;Jet OLEDB:Engine Type=5"
    JRO.CompactDatabase(source, compact)
    'delete orinal file
    System.IO.File.Delete(System.AppDomain.CurrentDomain.BaseDirectory & "Code7.accdb")
    'rename compact file to original file name
    File.Move(System.AppDomain.CurrentDomain.BaseDirectory & "newCode7.accdb", System.AppDomain.CurrentDomain.BaseDirectory & "Code7.accdb")
    MessageBox.Show("The database was compacted successfully")
user3001046
  • 235
  • 1
  • 10
  • 28

1 Answers1

1

There are 2 things wrong with this. The first and most important is that you need to tell JRO what kind of database you want to compact. You do this by appending...

    ;Jet OLEDB:Engine Type=5

to each connection string. That will eliminate your "Invalid Argument" error.

Second, your source and destination databases are the same. If you do this you will get another error, - "Database Exists". You must compact to a separate and distinct file.

Ciarán
  • 3,017
  • 1
  • 16
  • 20
  • i found some error like this when i input your code "Operation cannot be completed on this database because it uses attachements or multi-valued lookup fields.". – user3001046 Aug 14 '14 at 01:39
  • i have some question about destination , that file must be have in the same folder where database access file stay isn't it ? – user3001046 Aug 14 '14 at 03:02