CodeFluent 持久性争用条件


一旦

数据库由于某种原因变慢(长时间运行的查询、备份、性能分析器)

我的 Web 应用程序开始出现以下错误:

System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
   at System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command)
   at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at CodeFluent.Runtime.CodeFluentPersistence.InternalExecuteNonQuery(Boolean firstTry)
   at CodeFluent.Runtime.CodeFluentPersistence.InternalExecuteNonQuery(Boolean firstTry)
.... _> stack trace continues to my code

CodeFluent.Runtime.CodeFluentRuntimeException: CF1044: Nested persistence command is not supported. Current command: '[Contract_Search]', nested command: '[zref_template_document_LoadBlobFile]'.
   at CodeFluent.Runtime.CodeFluentPersistence.CreateStoredProcedureCommand(String schema, String package, String intraPackageName, String name)
   at CodeFluent.Runtime.BinaryServices.BinaryLargeObject.GetInputStream(CodeFluentContext context, Int64 rangeStart, Int64 rangeEnd)
.... _> stack trace continues to my code

第二个错误CF1044发生在我打开两个浏览器窗口并执行不同操作时。在一个中搜索,在另一个中生成文档。

很难复制。它永远不会以同样的方式发生。

某处有我无法弄清楚的竞争条件

以下是实际对我有用的东西:

public byte[] GetRtfDocumentStreamBuffer(TemplateDocumentType templateType, int culture)
{
    var template = TemplateDocument.LoadActiveByDocumentTypeAndLcid(DateTime.Today, templateType.Id, culture);
    var resultStream = new MemoryStream();
    using (var cf = CodeFluentContext.GetNew(Constants.MyApplicationStoreName))
    using (var templateStream = template.File.GetInputStream(cf, 0, 0))
    using (var resultWriter = new StreamWriter(resultStream, Encoding.GetEncoding("windows-1252")))
    {
        GenerateRtfDocument(....);
        resultWriter.Flush();
    }
    return resultStream.GetBuffer();
}

我在反编译的 cf 运行时中看到的CodeFluentContext.Dispose()调用CodeFluentPersistence.Dispose()关闭读取器和释放连接。

最新更新