数据库
首页 > 数据库> > C#-Quartz.NET配置-不与数据库交互

C#-Quartz.NET配置-不与数据库交互

作者:互联网

我对Quartz.net并不满意,并且正在编写Windows服务,因此,如果这个问题有点不了解,我深表歉意.

无论如何,我将Windows服务设置为使用quartz.net来运行另一个进行某些文件清除的Win​​dows服务.它的安装和运行都很好(至少根据installutil和net start命令),但是它从不向数据库添加任何内容.

我创建了数据库表,所有内容和数据库本身看起来都很好.然后,我创建了一个app.config,其中包含(我认为)我需要用来将其连接到db的所有配置设置.但是由于某种原因,数据库永远不会被触动.没有创建触发器(我显然是用代码创建的),没有排队的工作,什么也没有.

它是一个oracle数据库,所有权限都设置为允许读/写和所有操作.

这是app.config的源代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>

<quartz>

<add key="quartz.scheduler.instanceName" value="TestQuartzServer" />
<add key="quartz.scheduler.instanceId" value="instance_one" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.useProperties" value="false" />
<add key="quartz.jobStore.dataSource" value="default" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.clustered" value="true" />
<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.SimpleSemaphore, Quartz" />
<add key="quartz.dataSource.default.connectionStringName" value="ConnectionString" />
<add key="quartz.dataSource.default.provider" value="OracleClient-20" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" />
</quartz>
 <connectionStrings>
    <add name="ConnectionString" connectionString= "Server=localhost;Database=Quartz;Uid=Quartz;Pwd=Quartz" />
</connectionStrings>
</configuration>

这是应用程序源:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Triggers;
using System.Collections;

namespace PurgeScheduler1
{

    public partial class Service1 : ServiceBase
    {
        public static IScheduler _scheduler;
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            try {
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            _scheduler = schedulerFactory.GetScheduler();
            _scheduler.Start();
            AddJob();
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }


        protected override void OnStop()
        {
        }

        public static void AddJob()
        {
            IJob myJob = new MyJob();
            JobDetailImpl jobDetail = new JobDetailImpl("Purge", "Group1", myJob.GetType());
            CronTriggerImpl trigger = new CronTriggerImpl("Trigger1", "Group1", "When to run it goes here");
            SimpleTriggerImpl trigger1 = new SimpleTriggerImpl("Trigger2", 10, TimeSpan.FromMinutes(2));
            _scheduler.ScheduleJob(jobDetail, trigger1);
            DateTimeOffset? nextFireTime = trigger.GetNextFireTimeUtc();
            Console.WriteLine("Next Fire Time:" + nextFireTime.Value);
        }
    }
    internal class MyJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Console.WriteLine("In myJob class");
            Process.Start("correct path, but hiding it for proprietary reasons");
        }
    }
}

解决方法:

quartz.dataSource.default.connectionStringName

以上应为:
crystal.dataSource.default.connectionString

请尝试将“ quartz.jobStore.clustered”设置为false.缩小潜在问题.

您不再需要installutil. quartz已经为您提供了一个使用topshelf的开箱即用的服务器实现. Topshelf取代了您必须创建从ServiceBase继承的windowservice项目的麻烦.您可以使用以下命令安装默认服务:Quartz.Server.exe / install,但建议您使用Visual Studio调试器-因为它是您调试问题的控制台应用程序.

https://github.com/quartznet/quartznet
参见:Quartz.Server.2010.sln

只需要指定配置即可.

标签:quartz-net,configuration,c,net
来源: https://codeday.me/bug/20191201/2079658.html