ADO.NET with Quartz.NET

十年热恋 提交于 2019-12-05 10:47:46

Right, worked it out for anyone that needs help. My connection string was wrong, and I had to hard code the server information in as in Example 13 in the Quartz.NET examples. It's a great framework :)

I had similar problems with this and the web.config section seemingly being ignore unless I hard coded the properties for some reason. I didn't like this so in the end I wrote some code to load the properties from the web.config file and set them in my StdSchedulerProvider class instead.

//force the properties to be loaded from the web.config section
            NameValueCollection quartzSection = (NameValueCollection)ConfigurationManager.GetSection("quartz");
            if (quartzSection != null)
            {
                var quartzProperties = quartzSection.AllKeys.SelectMany(quartzSection.GetValues, (k, v) => new { key = k, value = v });

                foreach (var property in quartzProperties)
                {
                    properties.Add(property.key, property.value);
                }
            }

My web.config section is like this:

<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="SchedulingPOC"/>
        <add key="quartz.scheduler.instanceId" value="SchedulingPOC"/>

        <!-- Configure Thread Pool -->
        <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
        <add key="quartz.threadPool.threadCount" value="10" />
        <add key="quartz.threadPool.threadPriority" value="Normal" />

        <!-- Configure Job Store -->
        <add key="quartz.jobStore.misfireThreshold" value="60000" />
        <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
        <add key="quartz.jobStore.useProperties" value="true" />
        <add key="quartz.jobStore.dataSource" value="default" />
        <add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
        <add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />

        <add key="quartz.dataSource.default.connectionString" value="Server=.\SQLExpress;Database=QuartzPOC;Trusted_Connection=True;"/>

        <add key="quartz.dataSource.default.provider" value="SqlServer-20" />
      </quartz>

Quartz.net then started logging in the database as I wanted it to. No idea why it's so hard to get this working.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!