Thursday, January 5, 2012

Using Quartz.Net 2.0 With SQL Compact 4.0

NOTE: I'm now blogging at http://jayvilalta.com/blog and not updating this blog anymore. For information on the latest version of Quartz.Net, visit me there.

Now that SQL Compact 4.0 is out, you might want to use it to as your Quartz.Net job store. Here is how to set up a Quartz.Net 2.0 scheduler with a SQL Compact 4.0 database.
Prerequisites
First, you will need to download the SQL Compact 4.0 runtime and install it on the same box that will run the Quartz.Net scheduler. You can download the runtime directly from the Microsoft site. Be sure to download the correct version for the bit-ness of your operating system. Once it is installed, we’ll configure Quartz.Net to use it as the default job store.
Configuring Quartz.Net 2.0 to Use SQL Compact 4.0 as the Jobstore
By default, Quartz.Net uses a memory based jobstore. This means that all of the jobstore information (jobs, triggers, next fire times, etc.) is lost every time that the scheduler is stopped. A database job store lets you persist this information so that the next time the scheduler starts you will not need to create all of your job and trigger information.
To use a database as the jobstore, you need to set several configuration properties. Here is a sample configuration that uses SQL Compact 4.0 as the job store:
quartz.jobStore.type = Quartz.Impl.AdoJobStore.JobStoreTX, Quartz
quartz.jobStore.driverDelegateType = Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz
quartz.jobStore.dataSource = quartzDataSource
quartz.dataSource.quartzDataSource.connectionString = Data Source=C:\quartz\quartz.sdf;Persist Security Info=False;
quartz.dataSource.quartzDataSource.provider = SqlServerCe-400

Setting Up the Database File
You will need a SQL Compact 4.0 database file in which to store the job store information. You can either create the database yourself (that’s a whole separate post itself, which I might write if there is enough interest…) or you can just download this empty database that I have already created. Once you have your database file ready to go, just change the data source for the connection string to point to the location of your database file.
Starting the Scheduler
Let’s start our scheduler so that we can see what to expect. Here’s what the console output looks like when everything works correctly:
image
If you already have a running instance of the scheduler, this post should tell you all that need to do to get your scheduler to use SQL Compact 4.0 as a job store.