gpt4 book ai didi

sqlite - MVVMCross社区SQLite-Net插件-无法打开数据库

转载 作者:行者123 更新时间:2023-12-03 18:15:30 25 4
gpt4 key购买 nike

我正在尝试在Windows Phone 8.1上打开数据库文件(foo.db)。使用SQLite-Net插件时,出现以下SQLiteException:无法打开数据库文件:foo.db(CannotOpen)。

这是代码:

public Db(ISQLiteConnectionFactory factory)
{
try
{
const string fileName = "foo.db";
StorageFolder folder = ApplicationData.Current.LocalFolder;
using(this.connection = factory.Create(Path.Combine(folder.Path, fileName)))
{
//Do SOME STUFF
}
}
catch (Exception ex)
{
//SQLiteException: Could not open database file: foo.db (CannotOpen).
}

}


我已经验证了文件的路径。如果删除社区插件并使用SQLite-net,则不会发生任何异常。

哪里错了?

谢谢。

最佳答案

我不知道是否有帮助,但这就是我处理该问题的方式。

我已经在PlatformSpecific项目中创建了ISQLiteConnection,并将其注册为IOC的类型:

Mvx.RegisterType<ISQLiteConnection>(() => new SQLiteConnection(fullPathtoDbFile));


然后,在我的核心(PCL)项目中,我将其解决:

public ISQLiteConnection GetConnection()
{
if (_con == null)
{
_con = Mvx.Resolve<ISQLiteConnection>(); ;
}
return _con;
}



ISQLiteConnection是Cirrious.MvvmCross.Community.Plugins.Sqlite命名空间的一部分。

关于sqlite - MVVMCross社区SQLite-Net插件-无法打开数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26047437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com