无法连接到我的 sqlite 数据库
我有一个 Windows Phone 应用程序,正在尝试连接到数据库。数据库有效,我已验证。我正在使用 codeplex 的 sqlite 客户端来尝试连接。
首先,我使用“>添加>现有项目>”将数据库添加到我的项目中之后我尝试使用代码进行连接:
db = new SQLiteConnection(@"Database.db");
db.Open();
Debug.WriteLine("DB opened");
SQLiteCommand cmd = db.CreateCommand("SELECT * FROM Tags");
var lst = cmd.ExecuteQuery<Tags>();
foreach (Tags r in lst)
{
Debug.WriteLine(r.Tag);
}
Debug.WriteLine(":D");
我的 Tags 类如下所示:
public class Tags
{
public int id { get; set; }
public string Tag { get; set; }
}
我在 sqlite 项目中收到一个错误(在 Sqlite3.Vdbe Preparation()
中),说有 没有这样的表:Tags
。该表就在那里,我查看了数据库并且表的名称是正确的。
我做错了什么?
i have a windows phone application and am trying to connect to a database. The database is valid, i have verified. I am using codeplex's sqlite client to try to connect.
First i add my database to my project using ">add>Existing item>" and after that i try to connect using the code :
db = new SQLiteConnection(@"Database.db");
db.Open();
Debug.WriteLine("DB opened");
SQLiteCommand cmd = db.CreateCommand("SELECT * FROM Tags");
var lst = cmd.ExecuteQuery<Tags>();
foreach (Tags r in lst)
{
Debug.WriteLine(r.Tag);
}
Debug.WriteLine(":D");
My Tags class looks like this :
public class Tags
{
public int id { get; set; }
public string Tag { get; set; }
}
And i get an error in the sqlite project ( in Sqlite3.Vdbe Prepare()
) saying that there is no such table:Tags
. The table is there, i've viewed the database and the name of the table is correct.
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试提供完整路径而不仅仅是文件名。我相信 Windows Phone 没有“当前目录”,因此应用程序可能会在根文件夹中查找。
如果您向 SQLite 客户端提供一个不存在的文件,它会默默地为您创建一个空数据库并“连接”到该数据库。
Try supplying the full path instead of just the file name. I believe windows phone does not have a "current directory" so the application probably looks in the root folder.
If you supply a file that does not exist to the SQLite client, it will silently create an empty database for you and "connect" to that.
我发现我的数据库必须位于IsolatedStorage 中。这是我发现有用的示例 http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Native-Database-Programming-via-Sqlite-Client-for-Windows-Phone.aspx
i've found that my database must be in the IsolatedStorage. Here is a sample i found useful http://dotnetslackers.com/articles/silverlight/Windows-Phone-7-Native-Database-Programming-via-Sqlite-Client-for-Windows-Phone.aspx