以下是Quartz的XML配置部分:
<quartz>
<add key="quartz.scheduler.instanceName" value="DefaultQuartzScheduler" />
<!--Configure Thread Pool -->
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="1" />
<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.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>
<add key="quartz.jobStore.tablePrefix" value="[Quartz].QRTZ_" />
<add key="quartz.jobStore.dataSource" value="myDS" />
<add key="quartz.dataSource.myDS.connectionString" value="Data Source=(LocalDB)\v11.0; Initial Catalog=xxxxxx; Integrated Security=True;" />
<add key="quartz.dataSource.myDS.provider" value="SqlServer-20" />
当使用StdSchedulerFactory时,此配置文件当前有效:
var factory = new StdSchedulerFactory();
factory.Initialize();
我目前正在尝试使用现有配置并在代码中加载所有配置值。我正在使用NameValueCollection重载可以传递给StdSchedulerFactory(config)。
这是我的代码:
var quartzConfig = new NameValueCollection
{
{ "quartz.scheduler.instanceName", "DefaultQuartzScheduler" },
{ "quartz.threadPool.type", "Quartz.Simpl.SimpleThreadPool, Quartz" },
{ "quartz.threadPool.threadCount", "1" },
{ "quartz.threadPool.threadPriority", "Normal" },
{ "quartz.jobStore.misfireThreshold", "6000" },
{ "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" },
{ "quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" },
{ "quartz.jobStore.tablePrefix", "[Quartz].QRTZ_" },
{ "quartz.jobStore.dataSource", "myDS" },
{ "quartz.dataSource.myDS.connectionString", "Data Source=(LocalDB)\v11.0; Initial Catalog=xxxxxx; Integrated Security=True;" },
{ "quartz.dataSource.myDS.provider", "SqlServer-20" }
}
var factory = new StdSchedulerFactory(quartzConfig);
factory.Initialize();
在我的app.config文件中,我已经删除了该部分,假设我的代码现在正在加载所有配置值。
然而,当我去运行应用程序时,我不断获得:
Quartz.JobPersistenceException: Failed to obtain DB connection from data source 'myDS'
不太确定我是否正确行事。在app.config中使用代码而不是xml加载配置值时,我是否将emtpy部分保留在那里?我是否完全删除它?
不太清楚我在做什么,但我不能让Quartz以这种方式找到连接字符串。
答案 0 :(得分:2)
对于XML配置,这很好:
<add key="quartz.dataSource.myDS.connectionString" value="Data Source=(LocalDB)\v11.0; Initial Catalog=xxxxxx; Integrated Security=True;" />
对于代码配置,我必须在“\ v11.0”前面添加一个额外的“\”:
{ "quartz.dataSource.myDS.connectionString", "Data Source=(LocalDB)\\v11.0; Initial Catalog=IXRS_123456; Integrated Security=True;" }