You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 06:15:38