简体   繁体   English

Mono无法打开SQLite数据库

[英]Mono can't open sqlite database

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. 我正在尝试与sqlite v3数据库建立非常基本的连接,而我正在使用monodevelop 3.0和Mono 2.10,但无法连接至数据库。 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

Permissions look OK and I have the Sqlite3.dll in the project, and it seems to be working OK. 权限看起来不错,并且我在项目中有Sqlite3.dll,而且看来工作正常。 Have I missed anything obvious? 我是否错过任何明显的事情? I'm pretty good on the Visual Studio side, but still fairly fresh working in a Mono/Monodevelop environment. 我在Visual Studio方面相当不错,但是在Mono / Monodevelop环境中仍然可以新鲜工作。

What platform? 什么平台?

I don't believe you need to create a file. 我认为您无需创建文件。 If it's not found, iirc, it'll make the database file. 如果找不到iirc,它将创建数据库文件。

Fwiw, on a Mac, I'm doing (note URI to a pretty standard path; I haven't used Data Source )... Fwiw,在Mac上,我正在做(注意URI的标准路径;我没有使用过Data Source )...

using System;
using System.Data;
using Mono.Data.Sqlite;

namespace test
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            IDbConnection conTemp = null;
            IDbCommand cmdTemp = null;

            conTemp = (IDbConnection)new SqliteConnection ("URI=file:/Users/userName/mnmh.db");
            conTemp.Open ();
            cmdTemp = conTemp.CreateCommand ();         
            cmdTemp.CommandText = "SELECT * FROM employee";
            IDataReader drTemp = cmdTemp.ExecuteReader ();
            while (drTemp.Read()) {
                Console.WriteLine (drTemp.GetString (0));
            }


        }
    }
}

etc etc

Check the obvious -- you've referenced all the stuff you're using, etc. 检查显而易见的内容-您已引用了所有正在使用的东西,等等。

需要参考

Figured out my problem here. 在这里找出我的问题。 Apparently instead of using 显然不是使用

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

I should have been using 我应该一直在用

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

Switched to the URI and it works as expected. 切换到URI并按预期工作。 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. 通过阅读文档,我曾想过,在2.0概要文件下,需要DataSource部分而不是URI,但是我得到了想要的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM