ADO.NET 与 Quartz.NET

发布于 2024-09-25 08:59:19 字数 1480 浏览 5 评论 0原文

我将 Quartz.NET 与数据库一起使用,即 ADO.NET。问题是,当我的作业创建时,它们根本没有保存到数据库中。我配置的一切都正确吗?我使用的是 SQL Server Express,数据库的路径是“chris\sqlexpress.Quartz.dbo”。

配置文件的相关部分:

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

调度程序初始化和作业添加:

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));

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));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故笙诉离歌 2024-10-02 08:59:19

我遇到了类似的问题,并且 web.config 部分似乎被忽略,除非我出于某种原因对属性进行了硬编码。我不喜欢这样,所以最后我编写了一些代码来从 web.config 文件加载属性并将它们设置在我的 StdSchedulerProvider 类中。

//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);
                }
            }

我的 web.config 部分是这样的:

<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 然后开始按照我的意愿登录数据库。不知道为什么让这个工作这么难。

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.

孤独患者 2024-10-02 08:59:19

是的,为任何需要帮助的人解决了这个问题。我的连接字符串是错误的,我必须对服务器信息进行硬编码,如 Quartz.NET 示例中的示例 13 所示。这是一个很棒的框架:)

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 :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文