对不起,如果问题之前被问到,但我搜索得很好,以解决这个问题,我没有找到答案.
我在我的Xamarin表单项目(PCL)中使用SQLite处理本地数据库.
1-连接在iOS中运行良好但在android中我遇到了这个问题(无法打开数据库文件)
2-我使用了另一种创建连接路径的方法:
string documentsPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
string path = Path.Combine(documentsPath, "pbcare.db");
Run Code Online (Sandbox Code Playgroud)
通过这种方式,处理数据库时发生了异常......
public bool checkLogin (string email, string password)
{
if (DB.Table<User> ().Where (user => user.Email == email && user.Password == password)
.FirstOrDefault () != null) { // exception caught here
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
但是数据库中有表格.
注意:即使数据库文件不存在,第二种方式也会创建连接!