Reputation: 245
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")
Upvotes: 0
Views: 3505
Reputation: 3057
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.
Upvotes: 1