VistaDB 5
Example 






Filename of database to pack, including extension. May use a full path or a path relative to the current working directory (same as Data Source in a connection string).
RepairDatabase(String) Method
Pack a database in "Repair" mode: not aborting when errors are encountered but dropping data in order to move on. Should only attempt on a separate copy or with a separate backup of the database in case of excessive data loss from the Repair attempt. Repair is most useful for recovering from corrupted indexes with no other data corruption.
Syntax
'Declaration
 
Overloads Sub RepairDatabase( _
   ByVal fileName As System.String _
) 
'Usage
 
Dim instance As IVistaDBDDA
Dim fileName As System.String
 
instance.RepairDatabase(fileName)
void RepairDatabase( 
   System.string fileName
)
procedure RepairDatabase( 
    fileName: System.String
); 
function RepairDatabase( 
   fileName : System.String
);
void RepairDatabase( 
   System.string* fileName
) 
void RepairDatabase( 
   System.String^ fileName
) 

Parameters

fileName
Filename of database to pack, including extension. May use a full path or a path relative to the current working directory (same as Data Source in a connection string).
Remarks

If PackDatabase encounters an error in accessing the database data it will abort and leave the database intact. RepairDatabase, on the other hand, will disregard errors and proceed, but it may drop data which it was unable to reach because of an error. This can sometimes recover a database intact and repaired when the corruption and errors only affect indexes which can be rebuilt, but it can also result in some tables being partially or fully truncated (some or all rows lost). It is thus important to always have a another separate copy of the database before attempting a repair; nothing further can be recovered from the post-repaired copy of the database because it has never contained any other data, but it might be possible to recover more from the pre-repaired copy of the database using different tools.

Because errors in validating constraints such as Foreign Keys are ignored in a Repair and because some data could be lost it is possible that the data recovered may fail to satisfy Foreign Key constraints (such as missing rows from the parent table corresponding to FK values in a child table) and so on, so some checking and validation is usually necessary after a Repair operation.

RepairDatabase should not be done as an automatic recovery but rather as a user-initiated last-ditch attempt to recover when errors in the database prevent a PackDatabase from being able to complete. If the Repair also fails or results in excessive loss of data it may be necessary to revert to an older backup and/or contact support about attempting to recover more from a pre-repaired copy of the database.

Example
Sub Main()
	Dim DDAObj As VistaDB.DDA.IVistaDBDDA
	' We must have a valid DDA Object loaded to call Repair
	DDAObj = VistaDB.DDA.VistaDBEngine.Connections.OpenDDA()
	DDAObj.RepairDatabase("C:\test.vdb5", Nothing, Nothing)
	' Path does not have to be absolute, Dot Net looks in the current working directory by default.
	' The base of the encryption key is passed as a string
	DDAObj.RepairDatabase("test.vdb5", "pass.word", Nothing)
End Sub
IVistaDBDDA DDAObj = VistaDB.DDA.VistaDBEngine.Connections.OpenDDA();
try
{
	// Attempt to repair the database
	DDAObj.RepairDatabase("databasename.vdb5", null, null);
	// It is always a good practice to Pack the database after a repair.  Repair can leave the
	// constraints or other high level database data in a bad logical state.
	DDAObj.PackDatabase(rwdbName, null, false, null);
}
catch (System.Exception e)
{
	System.Diagnostics.Debug.WriteLine("Exception: " + e.ToString());
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IVistaDBDDA Interface
IVistaDBDDA Members
Overload List
Interface IVistaDBDDA
IVistaDBDDA.PackDatabase