/> Alle Tabellen werden ordnungsgemäß erstellt. /> Was fällt aus: < /strong> < /p>
Nach dem vollständigsten Schließen der App und der Wiedereröffnung ist die Datenbankdatei verschwunden. Ich habe versucht, über Geräteprotokolle zu debuggen, wenn Sie die App schließen. Die Protokolle schließen mit der IT- es sei denn, Sie können sie öffnen?
Code: Select all
public static async Task InitializeAsync()
{
if (_connection != null) return;
await _semaphore.WaitAsync();
try
{
if (_connection != null) return; // Double-check after acquiring lock
string dbPath = Path.Combine(FileSystem.AppDataDirectory, "BetterSQLite.db3");
//// Delete the database file if it exists (uncomment to enable)
//if (File.Exists(dbPath))
// File.Delete(dbPath);
_connection = new SQLiteAsyncConnection(dbPath);
// Create the tables if they don't exist
await _connection.CreateTablesAsync();
_logger?.LogInformation("SQLite database initialized successfully at {DbPath}", dbPath);
}
catch (Exception ex)
{
_logger?.LogError(ex, "Failed to initialize SQLite database");
throw new InvalidOperationException("Failed to initialize database", ex);
}
finally
{
_semaphore.Release();
}
}