2018-03-06 02:22:19 -05:00
|
|
|
|
using SharedLibrary.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Data.SqlServerCe;
|
|
|
|
|
|
|
|
|
|
namespace SharedLibrary.Database
|
|
|
|
|
{
|
|
|
|
|
public class Repair
|
|
|
|
|
{
|
|
|
|
|
public static void Run(ILogger log)
|
|
|
|
|
{
|
2018-03-13 17:30:22 -04:00
|
|
|
|
if (!System.IO.File.Exists($"{Utilities.OperatingDirectory}Database.sdf"))
|
|
|
|
|
return;
|
|
|
|
|
|
2018-03-06 02:22:19 -05:00
|
|
|
|
SqlCeEngine engine = new SqlCeEngine(@"Data Source=|DataDirectory|\Database.sdf");
|
|
|
|
|
if (false == engine.Verify())
|
|
|
|
|
{
|
|
|
|
|
log.WriteWarning("Database is corrupted.");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
engine.Repair(null, RepairOption.DeleteCorruptedRows);
|
|
|
|
|
}
|
|
|
|
|
catch (SqlCeException ex)
|
|
|
|
|
{
|
|
|
|
|
log.WriteError(ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|