Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Quartz.NET with a custom connection provider

Tags:

quartz.net

I'm trying to use Quartz.NET with ReliableDbProvider, to allow Quartz to connect to our Azure SQL databases without transient connection issues.

Here's the configuration I'm using (re-formatted for readability; I actually initialize them in a NameValueCollection...):

quartz.jobStore.dirverDelegateType:                Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz
quartz.jobStore.tablePrefix:                       QRTZ_
quartz.dataSource.default.connectionString:        Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Foo;Integrated Security=True
quartz.dataSource.default.connectionProvider.type: ReliableDbProvider.SqlAzure.SqlAzureProvider
quartz.jobStore.useProperties:                     true

When trying to create a scheduler, I get an exception

InvalidCastException: Unable to cast object of type ReliableDbProvider.SqlAzure.SqlAzureProvider to type Quartz.Impl.AdoJobStore.Common.IDbProvider.

I guess that's not so surprising - but how do I work around it? I took a look at the IDbProvider interface from Quartz, but it wasn't straightforward how to forward that to an instance of the ReliableDbProvider, as the latter did not implement all the features of the former.

What's the best way to use a custom connection provider that Quartz doesn't know about?

like image 259
Tomas Aschan Avatar asked Jan 17 '26 19:01

Tomas Aschan


1 Answers

It is a QUART.NET IDbProvider....

Quartz.Impl.AdoJobStore.Common.IDbProvider

Not just the some/any standard microsoft one.

(Which you kinda make mention of, but at the same time, it doesn't look like it really clicked as to what that means)

Somebody (out there in internet land ... or you) has to WRITE a concrete that supports Azure. To my knowledge, it hasn't been done.

Here is the list:

https://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/job-stores.html

Currently following database providers are supported:
SqlServer-20 - SQL Server driver for .NET Framework 2.0
OracleODP-20 - Oracle’s Oracle Driver
OracleODPManaged-1123-40 Oracle’s managed driver for Oracle 11
OracleODPManaged-1211-40 Oracle’s managed driver for Oracle 12
MySql-50 - MySQL Connector/.NET v. 5.0 (.NET 2.0)
MySql-51 - MySQL Connector/:NET v. 5.1 (.NET 2.0)
MySql-65 - MySQL Connector/:NET v. 6.5 (.NET 2.0)
SQLite-10 - SQLite ADO.NET 2.0 Provider v. 1.0.56 (.NET 2.0)
Firebird-201 - Firebird ADO.NET 2.0 Provider v. 2.0.1 (.NET 2.0)
Firebird-210 - Firebird ADO.NET 2.0 Provider v. 2.1.0 (.NET 2.0)
Npgsql-20 - PostgreSQL Npgsql

APPEND

Hmm. I found something interesting.

In the Quartz.Net source code, in this file:

\src\Quartz\Impl\AdoJobStore\Common\dbproviders.properties

or another place to see it

https://github.com/quartznet/quartznet/blob/master/src/Quartz/Impl/AdoJobStore/Common/dbproviders.properties

Database provider configuration data
Core information taken from Spring Framework .NET - All credits to their great work!

..

# SQL SERVER
quartz.dbprovider.SqlServer-20.productName=Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0
quartz.dbprovider.SqlServer-20.assemblyName=System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.connectionType=System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.commandType=System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.parameterType=System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.commandBuilderType=System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.parameterDbType=System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.parameterDbTypePropertyName=SqlDbType
quartz.dbprovider.SqlServer-20.parameterNamePrefix=@
quartz.dbprovider.SqlServer-20.exceptionType=System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
quartz.dbprovider.SqlServer-20.useParameterNamePrefixInParameterCollection=true
quartz.dbprovider.SqlServer-20.bindByName=true
quartz.dbprovider.SqlServer-20.dbBinaryTypeName=Image

So it may be possible to try and do the above mappings for Azure items. No idea how close you might get.

I was expecting to see something like

public class SqlServer20 : Quartz.Impl.AdoJobStore.Common.IDbProvider

but that led me to find the "dbproviders.properties" file.

like image 87
granadaCoder Avatar answered Jan 19 '26 18:01

granadaCoder