Here is how I set upp the database. I pass in the connection using DI:
var path = Path.Combine(Path.Combine(ApplicationData.Current.LocalFolder.Path, "mydb.sqlite"));
var connectionFactory = new Func<SQLiteConnectionWithLock>(() => new SQLiteConnectionWithLock(new SQLitePlatformWinRT(), new SQLiteConnectionString(path, storeDateTimeAsTicks: false)));
_connection = new SQLiteAsyncConnection(connectionFactory)
The repo that takes the connection in its CTOR:
private SQLiteAsyncConnection _connection;
public SqliteRepository(SQLiteAsyncConnection connection)
{
_connection = connection;
_connection.CreateTableAsync<User>();
_connection.CreateTableAsync<Car>();
}
And a method to insert a Car:
public async void CreateCar(Car car)
{
await _connection.InsertAsync(car);
}
When I call CreateCar I always get an exception that Sqlite is Busy. From what I can understand this is because another connection is open. Appearantly I can use something called SQLiteConnectionPool
in order to close a connection. Can someone point me in the right direction on how to do this?
Aucun commentaire:
Enregistrer un commentaire