SqlCeEngine.Repair Method

Repairs a corrupted database.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)


Public Sub Repair ( _
    connectionString As String, _
    options As RepairOption _
public void Repair (
    string connectionString,
    RepairOption options
void Repair (
    String^ connectionString, 
    RepairOption options
public void Repair (
    String connectionString, 
    RepairOption options
public function Repair (
    connectionString : String, 
    options : RepairOption


  • connectionString
    The local connection string to the database.
  • options
    The RepairOption to use when repairing the database.


If the repair method is invoked by using the RepairOption's DeleteCorruptedRows value, all corrupted pages are discarded from the database. This may result in significant data loss, but the data recovered using this option should be free from corruption.

If the repair method is invoked by using the RepairOption's RecoverCorruptedRows value, the database will attempt to read data from the corrupted pages. This potentially results in more data being recovered, but this option does not guarantee that the data recovered will be free of corruption.


Starting with SQL Server Compact 3.5 Service Pack 1 SP1, 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


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);

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Development Platforms

Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0
Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0

See Also


SqlCeEngine Class
SqlCeEngine Members
System.Data.SqlServerCe Namespace