VistaDB 6
VistaDB.DDA Namespace / IVistaDBDDA Interface / RepairDatabase Method / RepairDatabase(String,String,OperationCallbackDelegate) Method
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).
Encryption key for the database (not changing). Pass null for an unencrypted database.
OperationCallbackDelegate method for feedback of pack progress. May be null (Nothing) for no callback.
Example


In This Topic
    RepairDatabase(String,String,OperationCallbackDelegate) Method
    In This Topic
    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, _
       ByVal encryptionKeyString As System.String, _
       ByVal operationCallbackDelegate As OperationCallbackDelegate _
    ) 
    'Usage
     
    
    Dim instance As IVistaDBDDA
    Dim fileName As System.String
    Dim encryptionKeyString As System.String
    Dim operationCallbackDelegate As OperationCallbackDelegate
     
    instance.RepairDatabase(fileName, encryptionKeyString, operationCallbackDelegate)
    void RepairDatabase( 
       System.string fileName,
       System.string encryptionKeyString,
       OperationCallbackDelegate operationCallbackDelegate
    )

    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).
    encryptionKeyString
    Encryption key for the database (not changing). Pass null for an unencrypted database.
    operationCallbackDelegate
    OperationCallbackDelegate method for feedback of pack progress. May be null (Nothing) for no callback.
    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.vdb6", 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.vdb6", "pass.word", Nothing)
    End Sub
    IVistaDBDDA DDAObj = VistaDB.DDA.VistaDBEngine.Connections.OpenDDA();
    try
    {
    	// Attempt to repair the database
    	DDAObj.RepairDatabase("databasename.vdb6", 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