2012-05-25 104 views
3

我是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"); 
     } 
    } 
} 
+0

你有没有试过它:quartz.dataSource.default.connectionString? –

+0

@LeblancMeneses是的,对不起,我试过了。没有工作。实际上,这是我使用Windows服务的一个要求,因此该部分不会工作,或者 –

+0

topshelf是构建窗口服务的更好方法http://topshelf-project.com/documentation/command-line-syntax/如何建立石英默认服务。没有在本地运行代码,如果它不是quartz.dataSource.default.connectionString,我就不会有想法。祝你好运! –

回答

1

必须在您的app.config的configSections添加handeler:

<configSections> 
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
</configSections> 

您可以配置记录器进行一些调试。我使用NLog。 你可以找到一个实现here

+0

抱歉,那实际上是在那里 - 当我翻译源代码时,它只是没有翻转过来。我编辑了这个问题以表明它在那里。你还有其他建议吗? –

2

quartz.dataSource.default.connectionStringName

上面的应该是: quartz.dataSource.default.connectionString

请 'quartz.jobStore.clustered' 设置为false尝试。缩小潜在的问题。

你应该不是需要installutil了。石英提供了一个服务器实现已经为您开箱,使用顶部。 Topshelf取代你必须创建一个从ServiceBase继承的windowservice项目。您可以使用Quartz.Server.exe/install来安装默认服务,但会推荐使用visual studio调试器 - 因为它是一个控制台应用程序,供您调试问题。

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

只是需要指定的配置。