Link to home
Start Free TrialLog in
Avatar of Falk2
Falk2

asked on

repair & compact database?

Hi!

How can i do repair & compact in VB (with an Access-Database)?

Falke
Avatar of dekeldate
dekeldate

ASKER CERTIFIED SOLUTION
Avatar of VincentLawlor
VincentLawlor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ryan Chong
Hi Falk2,

Source from another expert:

You can also use the CompactDatabase method of the Microsoft Jet and Replication Objects (JRO) 2.1 JetEngine object to encrypt or decrypt a database. To use the JRO JetEngine object, you must set a reference to the Microsoft Jet and Replication Objects 2.1 object library. When you use the CompactDatabase method, you can't save the compacted (and optionally encrypted) database to the same name as the original database.

The CompactDatabase method takes two arguments to specify the source database and the destination database: SourceConnection and DestConnection. Both the SourceConnection and DestConnection arguments take the form of connection strings. Within the connection strings, you specify various connection properties to determine how the source database is opened and how the destination database is compacted. At a minimum, you must use the Data Source property in each connection string to specify the path and name of the database. Additionally, to encrypt the database, you must include the Jet OLEDB:Encrypt Database property in the connection string for the DestConnection argument. The following procedure uses these connection properties to encrypt the database specified by the strSourceDB argument to the path and name specified by the strDestDB argument:

Function EncryptDb(strSourceDB As String, _
                  strDestDB As String) As String
Dim jetEngine          As JRO.JetEngine
Dim strSourceConnect   As String
Dim strDestConnect     As String

' Build connection strings for SourceConnection and
' DestConnection arguments.
strSourceConnect = "Data Source=" & strSourceDB
strDestConnect = "Data Source=" & strDestDB & ";" & _
                  "Jet OLEDB:Encrypt Database=True"

Set jetEngine = New JRO.JetEngine

' Compact and encrypt the database specified by strSourceDB
' to the name and path specified by strDestDB.
jetEngine.CompactDatabase strSourceConnect, strDestConnect

Set jetEngine = Nothing
End Function

'Hope will help.

Avatar of Falk2

ASKER

thanks :)

Falke