加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – System.Data.SQLite无法加载扩展

发布时间:2020-12-15 08:14:08 所属栏目:百科 来源:网络整理
导读:我正在尝试在设置连接时加载新的json1扩展,但我一直收到此错误: SQL logic error or missing database The specified procedure could not be found. 这是我的代码: SQLiteConnection connection = (SQLiteConnection)session.Connection;connection.Enabl
我正在尝试在设置连接时加载新的json1扩展,但我一直收到此错误:

SQL logic error or missing database
The specified procedure could not be found.

这是我的代码:

SQLiteConnection connection = (SQLiteConnection)session.Connection;
connection.EnableExtensions(true);
Assembly assembly = Assembly.Load("System.Data.SQLite");
connection.LoadExtension(assembly.Location,"sqlite3_json_init");

我正在使用NHibernate,所以我只是在执行任何逻辑之前从会话中获取连接.

有什么我做错了吗?我也尝试加载SQLite.Interop.dll,然后调用sqlite3_json_init方法,但仍然无法正常工作.

我做了这个,它似乎仍然没有工作:

SQLiteConnection connection = (SQLiteConnection)session.Connection;
                connection.EnableExtensions(true);
                string path = "F:GitHubExampleProjlibsqliteSQLite.Interop.dll";
                if (File.Exists(path))
                {
                    connection.LoadExtension(path,"sqlite3_json_init");
                }

解决方法

从SQLite.Interop.dll加载扩展是正确的方法.所以你应该能够做到以下几点:
connection.EnableExtensions(true);
connection.LoadExtension(@"fullpathtoSQLite.Interop.dll","sqlite3_json_init");

我已经测试了它并且它正在工作,所以如果你仍有问题,你可能需要说明你是如何获得互操作文件的路径的.出于调试目的,可能在LoadExtension之前添加一个断言,以确保您尝试加载的互操作文件实际存在于您认为的位置.

还要确保你正在加载正确的版本(x86与x64.)如果你尝试了错误的版本,你会得到,“找不到指定的模块.”在LoadExtension调用,即使它实际上在那里.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读