我是Quartz.net的總編程人員,編寫Windows服務,所以我很抱歉如果這個問題有點不瞭解。Quartz.NET配置 - 不與db進行交互
無論如何,我設置了一個windows服務,以使用quartz.net運行另一個窗口服務,它執行一些文件清理。它安裝並運行得很好(至少根據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.connectionString? –
@LeblancMeneses是的,對不起,我試過了。沒有工作。實際上,這是我使用Windows服務的一個要求,因此該部分不會工作,或者 –
topshelf是構建窗口服務的更好方法http://topshelf-project.com/documentation/command-line-syntax/如何建立石英默認服務。沒有在本地運行代碼,如果它不是quartz.dataSource.default.connectionString,我就不會有想法。祝你好運! –