单开OS X:System.Data.SQLite不起作用 [英] Mono on OS X: System.Data.SQLite does not work

查看:277
本文介绍了单开OS X:System.Data.SQLite不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算做单使用和SQLite作为数据库的项目。发展是要在Mac上主要做了。我已经成功安装单和测试System.Data.SQLite(管理DLL)。简单的测试应用程序正常工作。



然而,当我试图在我的代码,它抛出一个运行时异常使用数据表。以下是代码片段:

 公共静态无效的主要(字串[] args)
{
串的connectionString =数据源= emp.db;

尝试{使用
(康涅狄格州SQLiteConnection =新SQLiteConnection(的connectionString))
{
查询字符串=SELECT名字,姓氏FROM雇员;使用(SQLiteCommand COMM =新SQLiteCommand(查询,康涅狄格州))
{
conn.Open()

;

comm.CommandText =查询;使用

(SQLiteDataReader读卡器= comm.ExecuteReader())
{
,而(reader.Read())
{
字符串名字=读者。 GetString的(0);
串姓氏= reader.GetString(1);
Console.WriteLine(姓名:+名字++姓氏);
}

DataTable的DT =新的DataTable();
dt.Load(读卡器); //其中出现
}
}
}
}赶上(例外五){
Console.WriteLine(五)问题39行;
}
}



上面的代码获得成功建造,但不上运行。我的机器,并给出了在终端上以下输出



当我运行应用程序的输出如下:

 名称:李四
名称:埃里克·史密斯
System.EntryPointNotFoundException:在(包装管理到本机)System.Data这sqlite3_column_origin_name
。 SQLite.UnsafeNativeMethods:在System.Data.SQLite.SQLite3.ColumnOriginalName(System.Data.SQLite.SQLiteStatement语句,的Int32指数)[0x00000] sqlite3_column_origin_name(IntPtr的,INT)
上述<文件名不明> 0
在System.Data.SQLite.SQLiteDataReader.GetSchemaTable(布尔wantUniqueInfo,布尔wantDefaultValue)[0​​x00000]上述<文件名不明> 0 $在System.Data.SQLite.SQLiteDataReader.GetSchemaTable b $ b()[0x00000]中<文件名不明>:在System.Data.Common.DataAdapter.BuildSchema(读者的IDataReader,System.Data.DataTable表的SchemaType的SchemaType,MissingSchemaAction missingSchAction,MissingMappingAction missingMapAction,System.Data.Common.DataTableMappingCollection dtMapping)0
[0x0003b]在System.Data.DataTable /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:284
.Load(IDataReader的读者,loadOption loadOption)0x0001f]在/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.Data/System.Data/DataTable.cs:2853
。在System.Data.DataTable.Load(IDataReader的读者)[0x00011]在/private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.Data/System.Data/DataTable.cs:在SQLiteApp.MainClass.Main 2838
(System.String []参数)[0x00086]在/Users/nayaabkhan/Projects/SQLiteApp/SQLiteApp/Main.cs:37

我很惊讶地看到,同样的上述可执行工作完全在Windows下,但没有我的机器上。



在互联网上搜索,我发现这个问题已经做sqlite的动态库的东西,必须与SQLITE_ENABLE_COLUMN_METADATA进行编译。我试图编译源码与SQLITE_ENABLE_COLUMN_METADATA为好。我不知道放在哪里编译 libsqlite3.0.dylib



任何帮助将不胜感激。


解决方案

您需要把dylib随时随地单可以找到它。



可以找出单做这个查找本机库:



<预类=郎BSH prettyprint-覆盖> 出口MONO_LOG_LEVEL =调试
出口MONO_LOG_MASK = DLL
单yourprogram.exe

和详细查找输出将被打印到终端。在我的系统单首先查找的目录中的可执行文件,所以把dylib有可能是最容易的。然后单要求系统找到dylib(通过尝试打开它没有路径)。该系统通常将在/ usr / lib目录,也许其他一些地方(这当然是与系统相关的),但在任何情况下,你可以添加一个路径,系统通过设置LD_LIBRARY_PATH这条道路的样​​子。在这种情况下,你会做这样的:



<预类=郎BSH prettyprint-覆盖> 导出LD_LIBRARY_PATH = /路径/要/ dylib: $ LD_LIBRARY_PATH
单yourprogram.exe


I am planning to do a project using Mono and SQLite as the database. Development is to be done primarily on a Mac. I have successfully setup Mono and tested System.Data.SQLite(managed dll). Simple test applications work perfectly.

However when I tried to use DataTable in my code it throws a runtime exception. Following is the code snippet:

public static void Main (string[] args)
{
    string connectionString = "Data Source=emp.db";

    try {
        using (SQLiteConnection conn = new SQLiteConnection(connectionString))
        {
            string query = "SELECT firstname, lastname FROM employees";

            using (SQLiteCommand comm = new SQLiteCommand(query, conn))
            {
                conn.Open();

                comm.CommandText = query;

                using (SQLiteDataReader reader = comm.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string firstname = reader.GetString(0);
                        string lastname  = reader.GetString(1);
                        Console.WriteLine("Name: " + firstname + " " + lastname);
                    }

                    DataTable dt = new DataTable();
                    dt.Load(reader);  // line 39 where problem occurs
                }
            }
        }
    } catch (Exception e) {
        Console.WriteLine(e);
    }
}

The above code get built successfully but does not run on my development machine and gives the following output on the terminal.

The output when I run the application is as below:

Name: John Doe
Name: Eric Smith
System.EntryPointNotFoundException: sqlite3_column_origin_name
  at (wrapper managed-to-native) System.Data.SQLite.UnsafeNativeMethods:sqlite3_column_origin_name (intptr,int)
  at System.Data.SQLite.SQLite3.ColumnOriginalName (System.Data.SQLite.SQLiteStatement stmt, Int32 index) [0x00000] in <filename unknown>:0 
  at System.Data.SQLite.SQLiteDataReader.GetSchemaTable (Boolean wantUniqueInfo, Boolean wantDefaultValue) [0x00000] in <filename unknown>:0 
  at System.Data.SQLite.SQLiteDataReader.GetSchemaTable () [0x00000] in <filename unknown>:0 
  at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType, MissingSchemaAction missingSchAction, MissingMappingAction missingMapAction, System.Data.Common.DataTableMappingCollection dtMapping) [0x0003b] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:284 
  at System.Data.DataTable.Load (IDataReader reader, LoadOption loadOption) [0x0001f] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.Data/System.Data/DataTable.cs:2853 
  at System.Data.DataTable.Load (IDataReader reader) [0x00011] in /private/tmp/monobuild/build/BUILD/mono-2.10.6/mcs/class/System.Data/System.Data/DataTable.cs:2838 
  at SQLiteApp.MainClass.Main (System.String[] args) [0x00086] in /Users/nayaabkhan/Projects/SQLiteApp/SQLiteApp/Main.cs:37

I was surprised to see that the same above executable worked perfectly under windows, but was failing on my development machine.

Searching on the internet, I found that this problem has to do something with the sqlite dynamic library and must be compiled with SQLITE_ENABLE_COLUMN_METADATA. I've tried to compile sqlite with the SQLITE_ENABLE_COLUMN_METADATA as well. I don't know where to put the compiled libsqlite3.0.dylib.

Any help will be appreciated.

解决方案

You need to put the dylib anywhere mono can find it.

You can find out where mono looks for native libraries by doing this:

export MONO_LOG_LEVEL=debug
export MONO_LOG_MASK=dll
mono yourprogram.exe

and verbose lookup output will be printed to the terminal. On my system mono looks first in the directory where the executable is, so putting the dylib there is probably the easiest. Then mono asks the system to find the dylib (by trying to open it without a path). The system typically looks in /usr/lib and maybe a few other places (this is of course system-dependent), but in any case you can add a path for the system to look in by setting LD_LIBRARY_PATH to that path. In this case you'll do this:

export LD_LIBRARY_PATH=/path/to/dylib:$LD_LIBRARY_PATH
mono yourprogram.exe

这篇关于单开OS X:System.Data.SQLite不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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