【发布时间】:2016-11-03 23:35:46
【问题描述】:
Frank A. Krueger 的SQLite.net PCL 让我大吃一惊。我正在尝试将它用作 Android 应用程序以及 ASP.NET MVC Web 应用程序的通用数据层。我在使用 Android 方面取得了一些成功,但在尝试将其用于网络应用程序时,我得到了以下异常:
You need to call SQLitePCL.raw.SetProvider(). If you are using a bundle package, this is done by calling SQLitePCL.Batteries.Init().
所以,我在控制器的构造函数中调用了这个 Init 函数,以及数据库初始化:
SQLitePCL.Batteries.Init();
var dbPath = Path.Combine(Constants.DataDir, "SdgData.sqlite3");
var sqliteConnection = new SQLiteConnection(dbPath);
var sdgSqlRepository = new SdgSqlRepository(sqliteConnection);
crm = new CrmManager(sdgSqlRepository);
但是,似乎 Init 甚至没有被调用 - 我在它上设置了一个断点以及对 Combine 的调用的下一行,第二个被击中而第一个甚至没有注意到。 (可能是因为Init 是PCL 库调用不适用于ASP.NET 平台?)
有没有办法在 ASP.NET Web 应用程序中运行 SQLite.net PCL,还是我必须寻找不同的数据源?
【问题讨论】:
-
您使用的是哪个 SQLitePCL 项目?那里有太多了。
-
弗兰克 A.克鲁格 - github.com/praeclarum/sqlite-net
标签: c# asp.net asp.net-mvc sqlite portable-class-library