Quartz.NET + SQLite Jobstore抛出JobPersistenceException - c#

当向调度程序添加作业或从调度程序中删除作业时,Quartz会偶尔抛出JobPersistenceException(在前面的SQLiteException之后)。

似乎值得注意的事情:

Quartz.NET 2.01 + System.Data.SQLite 1.0.66(在撰写本文时都是最新版本,都注意到有可用的SQLite 1.0.82二进制包)
如果当前没有执行任何作业/触发蜂鸣,也会引发异常(我正在监视Quartz侦听器)
作业是从UI上下文中手动添加的(我需要重复10到20次才能导致错误,但似乎完全是随机的)
只要我不触摸AddJob()/ DeleteJob(),一切似乎都运行良好(多个作业,并行执行,在应用程序重启后的持久性)。扩展测试后,我确定它与添加/删除作业无关。数据库锁定/访问问题是一个普遍的问题。

添加/删除作业时,是否有我不知道必须遵循的建议步骤?

我的ISchedulerFactory配置有什么问题吗? (见下文)

补充性

我尝试使用System.Data.SQLite 1.0.82,这使情况变得更糟。当Quartz执行Job时,我几乎总是收到“ SQLite错误(5):数据库被锁定”的消息。
Quartz.NET将System.Data.SQLite 1.0.56列为受支持的数据库提供程序,因此使用较新版本可能会遇到问题。但是,我不考虑从1.0.66返回,因为IIRC有很多改进/修复。
我看了一下2.0.1版本修订版(624)和当前文件头修订版(669)之间的Quartz.NET开发主干。似乎没有相关的修复程序。
我怀疑这是System.Data.SQLite问题。我偶然发现了几篇文章(关于不同的SQLite版本),提到内部对资源进行配置可能会出现一些问题,从而使数据库文件保持锁定状态。

补充2

现在,我放弃了。我尝试了很多事情,但必须继续进行开发。我切换到了另一个数据库类型(Firebird),到目前为止,它似乎可以与Quartz一起正常工作。

如果有人能够完成这项工作,无论如何我都希望听到。

--

例外详情:

Quartz.JobPersistenceException:“无法提交ADO.NET事务。数据库文件已锁定\ r \ n数据库已锁定”

叠放

bei Quartz.Impl.AdoJobStore.JobStoreSupport.CommitConnection(ConnectionAndTransactionHolder cth, Boolean openNewTransaction)
bei Quartz.Impl.AdoJobStore.JobStoreSupport.ExecuteInNonManagedTXLock(String lockName, Func`2 txCallback)
bei Quartz.Impl.AdoJobStore.JobStoreTX.ExecuteInLock(String lockName, Func`2 txCallback)
bei Quartz.Impl.AdoJobStore.JobStoreSupport.RemoveJob(JobKey jobKey)
bei Quartz.Core.QuartzScheduler.DeleteJob(JobKey jobKey)
bei Quartz.Impl.StdScheduler.DeleteJob(JobKey jobKey)

InnerException SQLiteException:“数据库文件已锁定\ r \ n数据库已锁定”

叠放

bei System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
bei System.Data.SQLite.SQLiteDataReader.NextResult()
bei System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
bei System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
bei System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
bei System.Data.SQLite.SQLiteTransaction.Commit()
bei Quartz.Impl.AdoJobStore.JobStoreSupport.CommitConnection(ConnectionAndTransactionHolder cth, Boolean openNewTransaction)

异常的来源是“ cth.Transaction.Commit();”。在此Quartz.NET方法中。

/// <summary>
/// Commit the supplied connection.
/// </summary>
/// <param name="cth">The CTH.</param>
/// <param name="openNewTransaction">if set to <c>true</c> opens a new transaction.</param>
/// <throws>JobPersistenceException thrown if a SQLException occurs when the </throws>
protected virtual void CommitConnection(ConnectionAndTransactionHolder cth, bool openNewTransaction)
{
    CheckNotZombied(cth);

    if (cth.Transaction != null)
    {
        try
        {
            IsolationLevel il = cth.Transaction.IsolationLevel;
            cth.Transaction.Commit();
            if (openNewTransaction)
            {
                // open new transaction to go with
                cth.Transaction = cth.Connection.BeginTransaction(il);
            }
        }
        catch (Exception e)
        {
            throw new JobPersistenceException("Couldn't commit ADO.NET transaction. " + e.Message, e);
        }
    }
}

这就是我创建ISchedulerFactory的方式:

public static ISchedulerFactory CreateSQLiteSchedFactory(SQLiteConnection sqlConn, string tablePrefix) {
    // db provider hinzufügen
    var metaData = new DbMetadata();
    metaData.AssemblyName = "System.Data.SQLite,Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139";
    metaData.BindByName = true;
    metaData.CommandBuilderType = typeof(SQLiteCommandBuilder);
    metaData.CommandType = typeof(SQLiteCommand);
    metaData.ConnectionType = typeof(SQLiteConnection);
    metaData.ExceptionType = typeof(SQLiteException);
    metaData.ParameterDbType = typeof(TypeAffinity);
    metaData.ParameterDbTypePropertyName = "DbType";
    metaData.ParameterNamePrefix = "@";
    metaData.ParameterType = typeof(SQLiteParameter);
    metaData.UseParameterNamePrefixInParameterCollection = true;
    DbProvider.RegisterDbMetadata("SQLite-1066", metaData);

    // konfiguration für factory erstellen
    NameValueCollection properties = new NameValueCollection();
    properties["quartz.scheduler.instanceName"] = "TestScheduler";
    properties["quartz.scheduler.instanceId"] = "instance_one";
    properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
    properties["quartz.threadPool.threadCount"] = "5";
    properties["quartz.threadPool.threadPriority"] = "Normal";
    properties["quartz.jobStore.misfireThreshold"] = "60000";
    properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
    properties["quartz.jobStore.useProperties"] = "false";
    properties["quartz.jobStore.dataSource"] = "default";
    properties["quartz.jobStore.tablePrefix"] = tablePrefix;
    properties["quartz.jobStore.clustered"] = "true";

    properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";

    properties["quartz.dataSource.default.connectionString"] = sqlConn.ConnectionString;
    properties["quartz.dataSource.default.provider"] = "SQLite-1066";

    // factory erzeugen
    return new StdSchedulerFactory(properties);
}

使用类似于“ Data Source = c:\ mydb.db; Version = 3;”的连接字符串创建SQLiteConnection。并使用提供的SQL脚本初始化所有石英表

参考方案

您必须在属性中将此设置为true:

properties["quartz.jobStore.txIsolationLevelSerializable"] = "true";

如何用Cython保持C++类名不变? - c++

我有一个名为Foo的C++类。如果遵循Cython C++ tutorial,则需要以其他方式调用Python类,例如PyFoo。但是我确实也需要调用Python类Foo。如何有效地做到这一点?编辑:我正在尝试接口以前与Boost Python接口的现有C++库。由于不同的原因,我想测试Cython。由于使用Boost:Python调用了Python类,因此…

jQuery发布不会将数据发布到ASP.NET API控制器 - javascript

我有一次噩梦般的时间通过jquery post将数据发送到ASP.NET Controller。这是JSON.stringify之后的数据:[{"scheduleTaskID":"203","task":"Permit","baselineDate":…

在Java中,执行“ ++++++++”表达式,编译器未报告任何错误并且可以正确执行? - java

我用eclipse编写了这段代码,用war写过,结果为3d。public static void main(String[] args) { double a = 5d + + + + + +-+3d; System.out.println(a); } 参考方案 您的表情可以改写为(5d) + (+ + + + +-+3d) 其中第一个+是应用于两个操作数的…

什么是用SWIG封装对象从C++调用Python函数的最干净方法是什么 - c++

我有以下代码,该代码通过Python回调函数实现了一个简单的C++类(ObjWithPyCallback)。想法是使用“this”作为单个参数来调用Python函数。问题在于,由于ObjWithPyCallback是SWIG包装的对象,因此我需要SWIG typeinfo才能创建Python对象。问题在于它在SWIG生成的文件“ObjWithPyCallba…

这个json格式正确吗? - c#

我尝试解析时有json数据,返回错误的语法错误,请帮助我发现语法错误。[{"isData":"Yes","Details":"[{"Id":"70","Name":"Test","FileName&#…