private void SetIdFromDb()
{
try
{
instance.WithDatabase(database, (session, dbid) =>
{
using (var details = new Table(session, dbid, "details", OpenTableGrbit.ReadOnly))
{
Api.JetMove(session, details, JET_Move.First, MoveGrbit.None);
var columnids = Api.GetColumnDictionary(session, details);
var column = Api.RetrieveColumn(session, details, columnids["id"]);
Id = new Guid(column);
var schemaVersion = Api.RetrieveColumnAsString(session, details, columnids["schema_version"]);
if (schemaVersion != SchemaCreator.SchemaVersion)
throw new InvalidOperationException("The version on disk (" + schemaVersion + ") is different that the version supported by this library: " + SchemaCreator.SchemaVersion + Environment.NewLine +
"You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.");
}
});
}
catch (Exception e)
{
throw new InvalidOperationException("Could not read db details from disk. It is likely that there is a version difference between the library and the db on the disk." + Environment.NewLine +
"You need to migrate the disk version to the library version, alternatively, if the data isn't important, you can delete the file and it will be re-created (with no data) with the library version.", e);
}
}