【问题标题】:.NET Core 2.0 Console App using Quartz.net 3.x and Sqlite 3.0.NET Core 2.0 控制台应用程序使用 Quartz.net 3.x 和 Sqlite 3.0
【发布时间】:2017-10-12 18:29:08
【问题描述】:

尝试在我的 Mac OSX Visual Studio 上编译的 .NET Core 2.0 控制台应用程序上使用具有以下配置的 Quartz 调度程序 3.0.0-alpha3 和 System.Data.Sqlite.Core (1.0.105.2) 使用 Sqlite:

NameValueCollection props = new NameValueCollection {
 { "quartz.threadPool.type", "Quartz.Simpl.SimpleThreadPool, Quartz" },
 { "quartz.threadPool.threadCount", "10" },
 { "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" },
 { "quartz.jobStore.misfireThreshold", "60000" },
 { "quartz.jobStore.lockHandler.type", "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" },
 { "quartz.jobStore.useProperties", "true" },
 { "quartz.jobStore.dataSource", "default" },
 { "quartz.jobStore.tablePrefix", "QRTZ_" },
 { "quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz" },
 { "quartz.dataSource.default.provider", "SQLite-10" },
 { "quartz.dataSource.default.connectionString", "Data Source=quartznet.db;Version=3;" }
};

实际行为

Quartz.SchedulerException:无法初始化数据源:SqliteDS ---> System.ArgumentOutOfRangeException:没有提供程序“SQLite-10”的元数据信息参数名称:providerName

在 Quartz.Impl.AdoJobStore.Common.DbProvider.GetDbMetadata(String providerName) 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\AdoJobStore\Common\DbProvider.cs:line 118 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\AdoJobStore\Common\DbProvider.cs:line 74 中的 Quartz.Impl.AdoJobStore.Common.DbProvider..ctor(String dbProviderName, String connectionString) 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\StdSchedulerFactory.cs:line 614 中的 Quartz.Impl.StdSchedulerFactory.d__65.MoveNext() --- 内部异常堆栈跟踪结束 --- 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\StdSchedulerFactory.cs:line 623 中的 Quartz.Impl.StdSchedulerFactory.d__65.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 Quartz.Impl.StdSchedulerFactory.d__69.MoveNext() 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\StdSchedulerFactory.cs:line 1118 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在 /Users/jakesmith/Projects/BackgroundProcessingWithQuartz/BackgroundProcessingWithQuartz/BackgroundProcessingWithQuartz/Program.cs:第 44 行中的 BackgroundProcessingWithQuartz.Program.d__1.MoveNext() [参见嵌套异常:System.ArgumentOutOfRangeException:提供者'SQLite-10 没有元数据信息' 参数名称:providerName 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\AdoJobStore\Common\DbProvider.cs:line 118 中的 Quartz.Impl.AdoJobStore.Common.DbProvider.GetDbMetadata(String providerName) 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\AdoJobStore\Common\DbProvider.cs:line 74 中的 Quartz.Impl.AdoJobStore.Common.DbProvider..ctor(String dbProviderName, String connectionString) 在 Quartz.Impl.StdSchedulerFactory.d__65.MoveNext() 在 C:\projects\quartznet-6fcn8\src\Quartz\Impl\StdSchedulerFactory.cs:line 614

我错过了什么?一切都是通过 NuGet 在我的 Visual Studio for Mac 上安装的。另外,当 dll 实际在 Mac 上运行时,为什么还要引用 C 驱动器。请帮忙。

【问题讨论】:

    标签: sqlite .net-core quartz.net


    【解决方案1】:

    Quartz 3.0 beta 1 支持 Microsoft.Data.Sqlite 开箱即用

    添加所需的包引用:

    PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />

    PackageReference Include="Quartz" Version="3.0.0-beta1" />

    class Program
    {
        static void Main()
        {
            try
            {
                Run().GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }
            finally
            {
                Console.ReadLine();
            }
        }
    
        private static async Task Run()
        {
            var properties = new NameValueCollection
            {
                ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
                ["quartz.jobStore.useProperties"] = "true",
                ["quartz.jobStore.dataSource"] = "default",
                ["quartz.jobStore.tablePrefix"] = "QRTZ_",
                ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz",
                ["quartz.dataSource.default.provider"] = "SQLite-Microsoft",
                ["quartz.dataSource.default.connectionString"] = "Data Source=test.db",
                ["quartz.serializer.type"] = "binary"
            };
    
    
            ISchedulerFactory sf = new StdSchedulerFactory(properties);
            IScheduler sched = await sf.GetScheduler();
    
            await sched.Start();
    
            Thread.Sleep(TimeSpan.FromMinutes(10));
        }
    }
    

    注册自定义提供者元数据

    仅当您需要 Microsoft.Data.Sqlite 以外的其他提供程序或使用比 beta 1 更早的版本时才需要

    您需要先注册元数据才能引用自定义 SQLite 提供程序。这是一个例子:

    项目文件:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.0</TargetFramework>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.Data.Sqlite" Version="2.0.0" />
        <PackageReference Include="Quartz" Version="3.0.0-alpha3" />
      </ItemGroup>
    </Project>
    

    代码:

    using System;
    using System.Collections.Specialized;
    using System.Data;
    using System.Threading;
    using System.Threading.Tasks;
    
    using Microsoft.Data.Sqlite;
    
    using Quartz;
    using Quartz.Impl;
    using Quartz.Impl.AdoJobStore.Common;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main()
            {
                Run().GetAwaiter().GetResult();
            }
    
            private static async Task Run()
            {
                DbProvider.RegisterDbMetadata("sqlite-custom", new DbMetadata()
                {
                    AssemblyName = typeof(SqliteConnection).Assembly.GetName().Name,
                    ConnectionType = typeof(SqliteConnection),
                    CommandType = typeof(SqliteCommand),
                    ParameterType = typeof(SqliteParameter),
                    ParameterDbType = typeof(DbType),
                    ParameterDbTypePropertyName = "DbType",
                    ParameterNamePrefix = "@",
                    ExceptionType = typeof(SqliteException),
                    BindByName = true
                });
    
    
                var properties = new NameValueCollection
                {
                    ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
                    ["quartz.jobStore.useProperties"] = "true",
                    ["quartz.jobStore.dataSource"] = "default",
                    ["quartz.jobStore.tablePrefix"] = "QRTZ_",
                    ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SQLiteDelegate, Quartz",
                    ["quartz.dataSource.default.provider"] = "sqlite-custom",
                    ["quartz.dataSource.default.connectionString"] = "Data Source=test.db",
                    ["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz",
                    ["quartz.serializer.type"] = "binary"
                };
    
    
                ISchedulerFactory sf = new StdSchedulerFactory(properties);
                IScheduler sched = await sf.GetScheduler();
    
                await sched.Start();
    
                Thread.Sleep(TimeSpan.FromMinutes(10));
            }
        }
    }
    

    您看到对 C 盘的引用是因为 Quartz 库是在 Windows 机器上编译的,这将使 PDB 文件包含来自构建主机的路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      相关资源
      最近更新 更多