I have a Xamarin Android app which creates SQLite DB. After reinstaling this app I am not able open the DB with a new version of the app. For the testing purpose the DB file is located at a Download folder. When the app is just updated not reinstaled it access the DB normaly.
A motivation: To get an independent DB file which could be used as a backup in case of moving app to another device.
EDIT:
App.xaml.cs:
public partial class App : Application
{
private readonly static string _dirPath = "/storage/emulated/0/Download/InventoryApp";
private static InvDB _database;
public static InvDB Database
{
get
{
if (_database == null)
{
string dbFileName = "InventoryDB.db3";
_database = new InvDB(Path.Combine(_dirPath, dbFileName));
}
return _database;
}
}
// ....
}
Database class constructor:
public class InvDB
{
readonly SQLiteAsyncConnection conn;
public const SQLite.SQLiteOpenFlags Flags =
SQLite.SQLiteOpenFlags.ReadWrite |
SQLite.SQLiteOpenFlags.Create |
SQLite.SQLiteOpenFlags.FullMutex;
public InvDB(string dbPath)
{
if(File.Exists(dbPath))
{
conn = new SQLiteAsyncConnection(dbPath, Flags);
conn.CreateTableAsync<Item>().Wait();
conn.CreateTableAsync<Room>().Wait();
}
}
// ....
}