官方配置持久化资料:http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/job-stores.html
持久化建库脚本位置:在下载的 quartz 源码 database/dbtables/tables_sqlite.sql 位置,使用 sqliteStudio 工具执行就行了1.下载源码(我下载的是 2.3.3.0 版本)
2.打开项目,找到 dbproviders.properties 文件 ,该文件是个嵌入资源
位置:Quartz\Impl\AdoJobStore\Common\dbproviders.properties
3.发现 quartz 2.3.3.0 支持 System.Data.sqlite.dll(1.0.88.0) 的驱动
4.查看自己的引用的(System.Data.sqlite.dll)是 1.0.102.0 版本,所以需要新加一个驱动描述。如下:
# sqlite3.0 provider quartz.dbprovider.sqlite-10102.assemblyName=System.Data.sqlite,Version=1.0.102.0,Culture=neutral,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.connectionType=System.Data.sqlite.sqliteConnection,System.Data.sqlite,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.commandType=System.Data.sqlite.sqliteCommand,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.parameterType=System.Data.sqlite.sqliteParameter,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.commandBuilderType=System.Data.sqlite.sqliteCommandBuilder,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.parameterDbType=System.Data.sqlite.TypeAffinity,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.parameterDbTypePropertyName=DbType quartz.dbprovider.sqlite-10102.parameterNamePrefix=@ quartz.dbprovider.sqlite-10102.exceptionType=System.Data.sqlite.sqliteException,PublicKeyToken=db937bc2d44ff139 quartz.dbprovider.sqlite-10102.useParameterNamePrefixInParameterCollection=true quartz.dbprovider.sqlite-10102.bindByName=true
5.编写一个函数在初始化 quartz 前调用
#region 数据库持久化job private static IScheduler _sched = null; /// <summary> /// 初始化数据库存储 /// </summary> public void InitDbStore() { //持久化配置参考 //http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/job-stores.html //添加驱动类型 //位置:\Quartz\Impl\AdoJobStore\Common\dbproviders.properties //1.首先创建一个作业调度池 var properties = new NameValueCollection(); //存储类型 properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX,Quartz"; //表明前缀 properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; //驱动类型 properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate,Quartz"; //数据源名称 string DBName = "quartz_storage"; string DbPath = Grass.Config.ConfigHelper.GetAppSettingsValue("quartz_storage"); //获取config中 quartz_storage 节点内容 //数据源名称 properties["quartz.jobStore.dataSource"] = DBName; //拼接连接属性名称 string conPropertieName = string.Format("quartz.dataSource.{0}.connectionString",DBName); //连接字符串 properties[conPropertieName] = string.Format("Data Source={0};Pooling=true;FailIfMissing=false;Version=3;UTF8Encoding=True;Journal Mode=DELETE;",DbPath); //拼接驱动属性名称 string proPropertieName = string.Format("quartz.dataSource.{0}.provider",DBName); properties[proPropertieName] = "sqlite-10102"; //新加的驱动名称 //Configuring AdoJobStore to use strings as JobDataMap values (recommended) properties["quartz.jobStore.useProperties"] = "true"; ISchedulerFactory sf = new StdSchedulerFactory(properties); _sched = sf.GetScheduler(); } #endregion6.配置config appsettings <add key="quartz_storage" value="E:\sqliteDb\quartz_storage.db"/> 原文链接:https://www.f2er.com/sqlite/198612.html