SQLite-无法打开数据库文件 [英] SQLite - Could not open database file

查看:1090
本文介绍了SQLite-无法打开数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编码Xamarin Android应用程序,并且在尝试创建SQLite数据库时遇到错误。

I am coding a Xamarin Android application, and am getting an error when trying to create a SQLite database.

这是我的代码:

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应用程序中使用相同的代码,并且想知道异常是否与包的名称?

I have the same code working in another Xamarin application and would like to know if the exception has something to do with the name of the package?

预先感谢

推荐答案

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

Does the path folder path that you are providing to SQLite exist? If you haven't created the CanFindLocation folder then opening a connection to that path will fail.

尝试:

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);

这篇关于SQLite-无法打开数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆