SqlCeEngine.Repair Method

Repairs a corrupted database.

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

public void Repair(
	string connectionString,
	RepairOption options


Type: System.String
The local connection string to the database.
Type: System.Data.SqlServerCe.RepairOption
The RepairOption to use when repairing the database.

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.


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

SqlCeEngine engine = new SqlCeEngine("Data Source = AdventureWorks.sdf");

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