Click to Rate and Give Feedback
TechNet
TechNet Library
SQL Server
SqlCeEngine Class
SqlCeEngine Methods
 Repair Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
SqlCeEngine..::.Repair Method

Repairs a corrupted database.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)
Visual Basic (Declaration)
Public Sub Repair ( _
    connectionString As String, _
    options As RepairOption _
)
Visual Basic (Usage)
Dim instance As SqlCeEngine
Dim connectionString As String
Dim options As RepairOption

instance.Repair(connectionString, options)
C#
public void Repair(
    string connectionString,
    RepairOption options
)
Visual C++
public:
void Repair(
    String^ connectionString, 
    RepairOption options
)
F#
member Repair : 
        connectionString:string * 
        options:RepairOption -> unit 
JScript
public function Repair(
    connectionString : String, 
    options : RepairOption
)

Parameters

connectionString
Type: System..::.String
The local connection string to the database.
options
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.

NoteNote

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

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

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

// Specify null destination connection string for in-place repair
//
engine.Repair(null, RepairOption.DeleteCorruptedRows);
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker