Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADO.NET with Quartz.NET

I'm using Quartz.NET with a database, i.e. ADO.NET. Problem is, when my jobs are created, they are not being saved to the database at all. Have I configured everything right? I am using SQL Server Express, and the path to my database is 'chris\sqlexpress.Quartz.dbo'.

Relevant parts of config file:

quartz.jobStore.type = Quartz.Impl.AdoJobStore.JobStoreTX, Quartz
quartz.jobStore.dataSource = default
quartz.jobStore.tablePrefix = QRTZ_
quartz.jobStore.clustered = true
quartz.jobStore.lockHandler.type = Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz
quartz.jobStore.driverDelegateType = Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz
quartz.dataSource.default.connectionString =
Server=localhost;Database=Quartz;Trusted_Connection=True;";
quartz.dataSource.default.provider = SqlServer-20
quartz.jobStore.useProperties = true

Scheduler initilisation and job addition:

ISchedulerFactory schedService = new StdSchedulerFactory();
IScheduler sched = schedService.GetScheduler();

JobDetail jobDetail = new JobDetail("1", "1", typeof(copyJob));
jobDetail.JobDataMap["initialPath"] = initpath;
jobDetail.JobDataMap["targetPath"] = targetpath;
jobDetail.JobDataMap["regex"] = regex;

CronTrigger trigger = new CronTrigger("trigger1", "group1", "1", "1", TextBox4.Text);
sched.AddJob(jobDetail, true);
DateTime ft = sched.ScheduleJob(trigger);
ft = TimeZoneInfo.ConvertTimeFromUtc(ft, trigger.TimeZone);

Response.Write(string.Format("{0} has been scheduled to run at: {1} and repeat based on expression: {2}", jobDetail.FullName, ft.ToString("r"), trigger.CronExpressionString));
like image 881
Chris Avatar asked Sep 29 '10 13:09

Chris


1 Answers

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.

like image 115
Adam Seabridge Avatar answered Oct 07 '22 17:10

Adam Seabridge