最近遇到作业调度问题,参考了很多关于“quartz.net”的资料,在配置“quartz.net持久化到sqlserver数据库”时遇到个问题“任务信息无法保存到数据库”:下面是我的代码示例:
1 using Quartz; 2 using Quartz.Impl; 3 using System; 4 using System.Collections.Generic; 5 using System.Collections.Specialized; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 10 namespace ConsoleApplication4 11 { 12 class Program 13 { 14 static void Main(string[] args) 15 { 16 try 17 { 18 DoJob(); 19 } 20 catch (SchedulerException se) 21 { 22 Console.WriteLine(se); 23 } 24 } 25 public static void DoJob() 26 { 27 //配置项 28 var properties = new NameValueCollection(); 29 properties["quartz.scheduler.instanceName"] = "TestScheduler"; 30 properties["quartz.scheduler.instanceId"] = "instance_one"; 31 properties["quartz.threadPool.type"] = 32 "Quartz.Simpl.SimpleThreadPool, Quartz"; 33 properties["quartz.threadPool.threadCount"] = "5"; 34 properties["quartz.threadPool.threadPriority"] = "Normal"; 35 properties["quartz.jobStore.misfireThreshold"] = "60000"; 36 properties["quartz.jobStore.type"] = 37 "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"; 38 properties["quartz.jobStore.useProperties"] = "true"; 39 properties["quartz.jobStore.dataSource"] = "default"; 40 properties["quartz.jobStore.tablePrefix"] = "QRTZ_"; 41 properties["quartz.jobStore.clustered"] = "true"; 42 // if running MS SQL Server we need this 43 properties["quartz.jobStore.lockHandler.type"] = 44 "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz"; 45 46 properties["quartz.dataSource.default.connectionString"] = 47 "Server=.;Database=quart;Trusted_Connection=True;"; 48 properties["quartz.dataSource.default.provider"] = "SqlServer-20"; 49 ISchedulerFactory sf = new StdSchedulerFactory(properties); 50 IScheduler sched = sf.GetScheduler(); 51 //2.创建出来一个具体的作业 52 IJobDetail jobInstance = JobBuilder.Create<HelloJob>().Build(); 53 //3.创建并配置一个触发器 54 ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create().StartAt(DateTime.SpecifyKind(DateTime.Now.AddSeconds(5), DateTimeKind.Local)).Build(); 55 //4.加入作业调度池中 56 sched.ScheduleJob(jobInstance, trigger); 57 //5.开始运行 58 sched.Start(); 59 Console.ReadKey(); 60 } 61 62 } 63 }
请熟悉quartz.net的大神们点拨点拨?怎么配置quartz.net的sqlserver连接信息?
https://github.com/wrx362114/EasyMQService
谢谢,不过我现在的问题是“如何成功配置quartz.net的sqlserver连接信息”哦?
@听海船说: 看配置文件.这个项目就是sqlserver持久化的.
https://github.com/wrx362114/EasyMQService/blob/master/src/ES.Service/App.config
@吴瑞祥: 恩,按照你给的方法,还是没保存到具体的作业信息,但是有一个悲观锁的表有数据了
@听海船说: 那个项目里不是有一个qz管理的东西嘛.你把他运行起来.在管理工具里看他qz的状态.