c# - SQLite - 如何摆脱恼人的跟踪消息 - "Native library pre-loader failed to get setting ... value"?

标签 c# sqlite sql-server-2008

我使用 SQL Server 2008 的 UDF 开发了一些 C# 程序集。 特别是我有一些使用 SQLite 数据库的函数。 我在那里添加了跟踪监听器来写入日志文件以查看内部发生的情况。 但有一个问题 - 每次调用 UDF 函数时,日志文件都会充满如下消息:

20160226,191636.67 [P5816]/[T4]  Native library pre-loader failed to get setting "No_PreLoadSQLite" value: System.ArgumentNullException: Value cannot be null.
Parameter name: path1
   at System.IO.Path.Combine(String path1, String path2)
   at System.Data.SQLite.UnsafeNativeMethods.GetXmlConfigFileName()
   at System.Data.SQLite.UnsafeNativeMethods.GetSettingValue(String name, String default)

我可以看到,每次调用时,它都会针对以下每个参数记录大约 18 条此类消息:

"No_PreLoadSQLite", "PreLoadSQLite_NoSearchForDirectory",  "PreLoadSQLite_ProcessorArchitecture",
"PreLoadSQLite_ProcessorArchitecture", "PreLoadSQLite_BaseDirectory",   "PreLoadSQLite_UseAssemblyDirectory",
"PreLoadSQLite_ProcessorArchitecture", "No_PreLoadSQLite", "PreLoadSQLite_NoSearchForDirectory",
"PreLoadSQLite_ProcessorArchitecture", "PreLoadSQLite_ProcessorArchitecture", "PreLoadSQLite_BaseDirectory",
"PreLoadSQLite_UseAssemblyDirectory", "PreLoadSQLite_ProcessorArchitecture", "No_SQLiteConnectionNewParser",
"DefaultFlags_SQLiteConnection", "No_SQLiteFunctions", "SQLite_ForceLogPrepare"

查看日志中的所有消息有点烦人,很难跟踪与我感兴趣的功能相关的日志消息。

您能否提供建议 - 我怎样才能摆脱那些额外/不需要的跟踪消息?

也许我需要执行一些特殊的 SQLlite API 调用来禁用所有这些设置的加载?

注意:为了使我的 UDF 程序集在 SQL Server CLR 引擎下工作,我复制了 SQLite.Interop.dllSystem.Data.SQLite.dll System.Data.SQLite.dll.config 文件放入 C:\Windows\system32。 正如您所看到的,System.Data.SQLite.dll.config 文件与 System.Data.SQLite.dll 位于同一目录,但它没有帮助。

注意:两个 DLL SQLite.Interop.dllSystem.Data.SQLite.dll 的版本均为 1.0.99.0。

提前谢谢您。

最佳答案

尽管我使用 Fody/Costura,但我也遇到了同样的问题将 System.Data.SQLite 库嵌入到我的程序集中(不清楚您是否在做类似的事情)。

您显示的错误来自 this code :

private static string GetXmlConfigFileName()
{
    string directory;
    string fileName;

#if !PLATFORM_COMPACTFRAMEWORK
    directory = AppDomain.CurrentDomain.BaseDirectory;
    fileName = Path.Combine(directory, XmlConfigFileName);

    if (File.Exists(fileName))
        return fileName;
#endif

    directory = GetAssemblyDirectory();
    fileName = Path.Combine(directory, XmlConfigFileName);

    if (File.Exists(fileName))
        return fileName;

    return null;
}

如果 GetAssemblyDirectory 方法无法确定程序集的路径,则返回 null,这将导致 Path.Combine 抛出异常。就我而言,由于 Costura 从流加载其程序集,因此它们没有目录,因此 GetAssemblyDirectory 失败。

好消息是我 opened a ticket with System.Data.SQLite并且它几乎立即就被修复了。希望它很快就会被推出。

关于c# - SQLite - 如何摆脱恼人的跟踪消息 - "Native library pre-loader failed to get setting ... value"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35659171/

相关文章:

sql-server - 在 sql 函数中使用设置语言

c# - 如何在 C# 中解析 XML 文件(youtube api 结果)?

sql - 在 sqlite3 中删除级联

sql-server - 运行在管理工作室中运行良好的脚本时出现 SQLCMD 语法错误

使用 Windows DFS 复制进行 SQLite 备份

ios - 如何创建用于 Core Data 的 sqlite 数据库?

sql-server - SQL Server 全文搜索语法

c# - 如何对数据集进行排序?

c# - 使用 Table per Type 的 EF4 继承问题

c# - Entity Framework - 不同环境下的不同行为