Xamarin Android 12创建离线存储遇SQLite URI连接配置异常求助
问题原因分析
- URI格式连接字符串不被支持:在Android平台上,
Microsoft.DataSync.Client.SQLiteStore并不支持URI格式的数据库连接字符串。你当前使用的file:/{dbPath}?mode=rwc属于URI写法,这会触发SQLite配置错误。 - 平台适配限制:Android系统内置的SQLite库默认未启用URI连接模式,而
OfflineSQLiteStore在Android环境下的实现基于系统SQLite,无法直接通过URI参数配置连接模式。
修复方案
直接传入普通文件路径即可,无需使用URI格式,OfflineSQLiteStore会自动处理Android平台的数据库连接逻辑:
var dbPath = Path.Combine(FileSystem.AppDataDirectory, "devstore.db"); var lcStore = new OfflineSQLiteStore(dbPath);
注:如果需要配置读写模式等参数,可通过
SQLiteConnectionSettings传入,而非URI参数。示例代码:
var settings = new SQLiteConnectionSettings(dbPath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex); var lcStore = new OfflineSQLiteStore(settings);
内容的提问来源于stack exchange,提问作者Abhi
相关产品推荐
相关产品推荐

