Sdílet prostřednictvím


SqlCeEngine.Repair Method

Repairs a corrupted database.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

Syntax

'Declaration
Public Sub Repair ( _
    connectionString As String, _
    options As RepairOption _
)
'Usage
Dim instance As SqlCeEngine
Dim connectionString As String
Dim options As RepairOption

instance.Repair(connectionString, options)
public void Repair(
    string connectionString,
    RepairOption options
)
public:
void Repair(
    String^ connectionString, 
    RepairOption options
)
member Repair : 
        connectionString:string * 
        options:RepairOption -> unit 
public function Repair(
    connectionString : String, 
    options : RepairOption
)

Parameters

  • connectionString
    Type: System.String
    The local connection string to the database.

Remarks

There are 4 values of RepairOption that can be used to repair the corrupted database:

  • RecoverAllPossibleRows

  • RecoverAllOrFail

  • DeleteCorruptedRows

  • RecoverCorruptedRows: This option is deprecated, as it does not ensure that the recovered data is free from corruption. You should use RecoverAllOrFail.

Note

In SQL Server Compact 4.0, you can use this method to create a repaired database with a case-sensitive collation. If you set the connection string property CaseSensitive to false in the Repair method, for a case sensitive database, if the database contains a case sensitive index, the loss of case sensitivity can cause an index error in the repair log even though the code runs successfully. The error occurs when two unique records are treated as equal. Two example values are 'aaa' and 'aaA'. The following message is written to the repair log file: Failed to create index

Examples

Dim engine As New SqlCeEngine("Data Source = AdventureWorks.sdf")

' Specify null destination connection string for in-place repair
'
engine.Repair(Nothing, RepairOption.DeleteCorruptedRows)
SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");

// Specify null destination connection string for in-place repair
//
engine.Repair(null, RepairOption.DeleteCorruptedRows);

See Also

Reference

SqlCeEngine Class

System.Data.SqlServerCe Namespace