I have used C# System.Data.SqlServerCe
version 3.5.1.0 to create a .SDF
database file. On opening the connection after creation, I sometimes receive the following error:
The database file may be corrupted. Run the repair utility to check the database file. [ Database name = \?\C:\SomeDatabase.sdf ]
Where is the "repair utility?" How do we use it?
I have searched Google and StackOverflow for answers:
This MSDN article talks about doing it programmatically. Is there a command line method?
Here is a small C#.NET Console App that works:
class Program
{
static void Main(string[] args)
{
SqlCeEngine engine =
new SqlCeEngine("Data Source = C:\\Users\\SomeUser\\Documents\\SomeDB.sdf");
if (false == engine.Verify())
{
Console.WriteLine("Database is corrupted.");
try
{
engine.Repair(null, RepairOption.DeleteCorruptedRows);
}
catch(SqlCeException ex)
{
Console.WriteLine(ex.Message);
}
}
Console.WriteLine("Press any key to continue.");
Console.ReadLine();
}
}
Find further options in this MSDN Article. Execute in the command prompt with ScriptCs.
You can use my sqlcecmd Tool to do this without writing any code. https://github.com/erikej/sqlcecmd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With