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

问题描述

我正在尝试与sqlite v3数据库建立非常基本的连接,而我正在使用monodevelop 3.0和Mono 2.10,但无法连接至数据库.我可以使该应用创建数据库,但是随后尝试连接该数据库将立即失败.有什么建议?我开始使用其他数据库,但后来决定让我的应用尝试创建一个空数据库,然后连接到该数据库.这似乎仍然失败.

I'm attempting to do a very basic connection to a sqlite v3 database and I'm using monodevelop 3.0 and Mono 2.10 and am unable to get connected to the database. I can make the app create the database, but then it immediately fails attempting to connect to it. Any suggestions? I had started with a different database, but then decided to have my app attempt to create a database empty and then connect to it. This still seems to fail.

SqliteConnection.CreateFile("db\\DataWorksProg.s3db");
SqliteConnection conn = new SqliteConnection("Data Source=file:db\\DataWorksProg.s3db");
conn.Open();

这小段代码失败,并显示有关无法打开数据库文件的错误.

This small piece of code fails with an error about not being able to open the database file.

Mono.Data.Sqlite.SqliteException: Unable to open the database file

权限看起来不错,并且我在项目中有Sqlite3.dll,而且看来工作正常.我是否错过任何明显的事情?我在Visual Studio方面相当出色,但是在Mono/Monodevelop环境中仍然可以很新鲜地工作.

Permissions look OK and I have the Sqlite3.dll in the project, and it seems to be working OK. Have I missed anything obvious? I'm pretty good on the Visual Studio side, but still fairly fresh working in a Mono/Monodevelop environment.

推荐答案

在这里找出了我的问题.显然不是使用

Figured out my problem here. Apparently instead of using

"Data Source=file:db\\DataWorksProg.s3db"

我应该一直在使用

"URI=file:db\\DataWorksProg.s3db"

切换到URI,它可以按预期工作.通过阅读文档,我曾想过,在2.0配置文件下,需要DataSource部分而不是URI,但是我得到了想要的结果.

Switched to the URI and it works as expected. I had thought from reading the docs that under the 2.0 profile, the DataSource part was needed instead of the URI, but I got the results I'm looking for.

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

07-22 14:54
查看更多