用LocalDb配置Quartz的AdoJobStores

本文关键字:AdoJobStores Quartz 配置 LocalDb | 更新日期: 2023-09-27 18:05:29

我一直在使用石英AdoJobStores与SQL Server很长一段时间没有任何问题。最近,我将SQL Server数据库更改为LocalDB数据库,并收到以下异常:

Quartz.JobPersistenceException: Couldn't obtain job names: Invalid object name 'QRTZ_JOB_DETAILS'.
System.Data.SqlClient.SqlException: Invalid object name 'QRTZ_JOB_DETAILS'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at Quartz.Impl.AdoJobStore.StdAdoDelegate.SelectJobsInGroup(ConnectionAndTransactionHolder conn, GroupMatcher`1 matcher) 
at Quartz.Impl.AdoJobStore.JobStoreSupport.GetJobNames(ConnectionAndTransactionHolder conn, GroupMatcher`1 matcher)

这是我的App.config中的Quartz配置部分:

<quartz>
<add key="quartz.scheduler.instanceName" value="RemoteServer" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="Normal" />
<add key="quartz.scheduler.exporter.type" value="Quartz.Simpl.RemotingSchedulerExporter, Quartz" />
<add key="quartz.scheduler.exporter.port" value="9999" />
<add key="quartz.scheduler.exporter.bindName" value="QuartzScheduler" />
<add key="quartz.scheduler.exporter.channelType" value="tcp" />
<add key="quartz.scheduler.exporter.channelName" value="httpQuartz" />
<add key="quartz.scheduler.instanceId" value="instance_one" />
<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.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
<add key="quartz.dataSource.default.connectionString" value="Data Source=(localdb)'v11.0; Initial Catalog=Scheduling;MultipleActiveResultSets=true;Integrated Security=SSPI" />
<add key="quartz.dataSource.default.provider" value="SqlServer-20" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />

数据库存在,我可以使用Navicat连接到它,但没有任何表是空的。我想也许我可以成为数据库提供者,阅读Quartz页面。. NET第9课:JobStores我发现这些是可用的数据库提供程序:

  • SqlServer-20 - SQL Server driver for .NET Framework 2.0
  • OracleODP-20 - Oracle的Oracle驱动程序
  • OracleODPManaged-1123-40 Oracle的托管驱动
  • OracleODPManaged-1211-40 Oracle的托管驱动
  • MySQL -50 - MySQL Connector/。. NET v. 5.0NET 2.0)
  • MySQL -51 - MySQL Connector/:NET v. 5.1NET 2.0)
  • MySQL -65 - MySQL Connector/:NET v. 6.5NET 2.0)
  • SQLite-10 - SQLite ADO。. NET 2.0 Provider v. 1.0.56NET 2.0)
  • 火鸟-201 -火鸟ADO. NET 2.0 Provider v. 2.0.1NET 2.0)
  • 火鸟-210 -火鸟ADO。. NET 2.0 Provider v. 2.1.0NET 2.0)
  • Npgsql-20 - PostgreSQL Npgsql

  1. 我可以使用LocalDB数据库与SQLServerDelegate?
  2. 问题是给定的,因为石英没有提供LocalDB?

用LocalDb配置Quartz的AdoJobStores

如果您连接到"(localdb)'v11.0"通过SSMS (Sql Server Management Studio)…您可以创建一个新的数据库(例如QuartzDB)。然后运行脚本创建它。

我找到了这个脚本谷歌搜索

https://www.google.com/search?q=%22CREATE +表+ % 5 bdbo % d % 5 bqrtz_calendars % 5 d % 22

这是我找到的一个:

https://raw.githubusercontent.com/quartznet/quartznet/master/database/tables/tables_sqlServer.sql

或者这个

https://github.com/quartznet/quartznet/blob/main/database/tables/tables_sqlServer.sql

我认为你可以使用石英库对该数据库,使用SqlServer-20。注意,并不是每个版本的sql-server都有提供程序,'SqlServer-20'适用于'最小公分母'的多个版本的sql-server。方式类型

我认为最重要的是……石英库不创建表/DDL,它使用已经创建的DDL。