When xamarin uses SQLite, the corresponding access path is different for each platform and needs to be referenced separately. The code is listed on the following platforms:
Windows8.1:
public SQLiteConnection GetConnection (string dbName) {
var sqliteFilename = string.Format ("{0} .db3", dbName);
string documentsPath = global :: Windows.Storage.ApplicationData.Current.LocalFolder.Path;
var path = Path.Combine (documentsPath, sqliteFilename);
return new SQLite.SQLiteConnection (path);
}
UWP:
public SQLiteConnection GetConnection (string dbName) {
var sqliteFilename = string.Format ("{0} .db3", dbName);
string documentsPath = global :: Windows.Storage.ApplicationData.Current.LocalFolder.Path;
var path = Path.Combine (documentsPath, sqliteFilename);
return new SQLite.SQLiteConnection (path);
}
Android:
public SQLite.SQLiteConnection GetConnection (string dbName)
{
var sqliteFilename = string.Format ("{0} .db3", dbName);
string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
var path = Path.Combine (documentsPath, sqliteFilename);
return new SQLite.SQLiteConnection (path);
}
IOS:
public SQLite.SQLiteConnection GetConnection (string dbName)
{
var sqliteFilename = string.Format ("{0} .db3", dbName);
string documentsPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); // Documents folder
string libraryPath = Path.Combine (documentsPath, "..", "Library"); // Library folder
var path = Path.Combine (libraryPath, sqliteFilename);
return new SQLite.SQLiteConnection (path);
}
xamarin SQLite path