Please save the db file fto the application's local storage on each platform. We cannot get and read the db file if it's stored as embedded resource. However, the initialization of 'SQLiteAsyncConnection' requires the file path. The embedded file is embedded as a resource in the assembly, it doesn't have a valid path. This is the first time I have tried to do this. I guess that I must be doing something fundamentally wrong unfrotunately. Return await AttemptAndRetry(() => databaseConnection.GetAsync(1)) Var databaseConnection = await GetDatabaseConnection().ConfigureAwait(false) Static TimeSpan pollyRetryAttempt(int attemptNumber) => TimeSpan.FromMilliseconds(Math.Pow(2, attemptNumber)) Return Policy.Handle().WaitAndRetryAsync(numRetries, pollyRetryAttempt).ExecuteAsync(action) Protected static Task AttemptAndRetry(Func> action, int numRetries = 10) If (!(x => x.MappedType = typeof(T)))Īwait DatabaseConnection.CreateTablesAsync(CreateFlags.None, typeof(T)).ConfigureAwait(false) Protected static async ValueTask GetDatabaseConnection() Static SQLiteAsyncConnection DatabaseConnection => _databaseConnectionHolder.Value Static readonly Lazy _databaseConnectionHolder = new Lazy(() => new SQLiteAsyncConnection(_databasePath, SQLiteOpenFlags.ReadOnly )) Static readonly string _databasePath = "" The code I'm using is as follows using System I have also tried this with as I am trying to debug on an iPhone device. I am attempting to use the database path of "" (where SLFinder is the namespace and SFMain.db is the name of the file). This is failing with a SQLite.SQLiteException of "Could not open database file. I am trying to load the large prebuilt SQLite database as an embedded resource and open it as a readonly database. However the small config database is located in the AppDataDirectory so has read/write access. I have got this method to work (with read/write flags rather than the readonly flag I show below) for the locally written SQLite configuration database, so I know that in principle this method works. I have created an abstract class for creating a database connection (with thanks to an article by Brandon Minnick on efficiently doing this). Just as an aside, I also create and access a small local SQLite database to hold configuration data. ![]() This database is around 160mb so clearly it is important that multiple copies are not produced / held and also it should ideally not have to be copied into different locations at runtime. ![]() I want that app to access a large read-only SQLite database that should be downloaded with the installation files. ![]() I am writing a Xamarin Forms app for use with iOS and Android. There are numerous questions raised about this topic here and on Google but I still can't find an answer the works for me :-( I am hoping someone can point me in the right direction on this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |