IW4M-Admin/SharedLibrary/Database/Repair.cs

29 lines
811 B
C#
Raw Normal View History

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