Skip to content

Instantly share code, notes, and snippets.

@lahma
Last active October 26, 2018 06:46
Show Gist options
  • Save lahma/56851f6eac1cc6d5f4f8e59f401c967c to your computer and use it in GitHub Desktop.
Save lahma/56851f6eac1cc6d5f4f8e59f401c967c to your computer and use it in GitHub Desktop.
Npgsql 3.0 with Quartz.NET 2.x - programmatic provider registration
// reference Npgsql NuGet package v3 in project
using Npgsql;
using NpgsqlTypes;
// register provider with name Npgsql-30, Quartz V3 has this OOTB
// could also just do a assembly binding redirect
DbProvider.RegisterDbMetadata("Npgsql-30", new DbMetadata
{
AssemblyName = typeof(NpgsqlConnection).Assembly.FullName,
BindByName = true,
ConnectionType = typeof(NpgsqlConnection),
CommandType = typeof(NpgsqlCommand),
ParameterType = typeof(NpgsqlParameter),
CommandBuilderType = typeof(NpgsqlCommandBuilder),
ParameterDbType = typeof(NpgsqlDbType),
ParameterDbTypePropertyName = "NpgsqlDbType",
ParameterNamePrefix = ":",
ExceptionType = typeof(NpgsqlException),
UseParameterNamePrefixInParameterCollection = true
});
var properties = new NameValueCollection
{
["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz",
["quartz.jobStore.dataSource"] = "default",
["quartz.dataSource.default.connectionString"] = "Server=127.0.0.1;Port=5432;Userid=postgres;Password=postgres;Pooling=true;MinPoolSize=1;MaxPoolSize=20;Timeout=15;SslMode=Disable;Database=quartz",
["quartz.dataSource.default.provider"] = "Npgsql-30"
};
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment