android – SQLite – 无法打开数据库文件

我正在编写一个Xamarin Android应用程序,并在尝试创建SQLite数据库时遇到错误.

这是我的代码:

string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CanFindLocation");
string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "CanFindLocation.db");
SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized);
var db = new SQLiteConnection (databaseFileName);

这是我得到的错误:

SQLite.SQLiteException: Could not open database file: /data/data/com.xamarin.docs.android.mapsandlocationdemo2/files/CanFindLocation/CanFindLocation.db (CannotOpen)

我有相同的代码在另一个Xamarin应用程序中工作,并想知道该异常是否与包的名称有关?

提前致谢

您提供给SQLite的路径文件夹路径是否存在?如果尚未创建CanFindLocation文件夹,则打开与该路径的连接将失败.

尝试:

string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "CanFindLocation");

// Create the folder path.
System.IO.Directory.CreateDirectory(applicationFolderPath);

string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "CanFindLocation.db");
SQLite.SQLite3.Config(SQLite.SQLite3.ConfigOption.Serialized);
var db = new SQLiteConnection (databaseFileName);
相关文章
相关标签/搜索