0

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

我的 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当我打开两个浏览器窗口并执行不同的操作时,会发生第二个错误。在一个中搜索,在另一个中生成文档。

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

我无法弄清楚的地方存在竞争条件。

4

1 回答 1

1

这实际上对我有用:

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()

于 2016-06-10T11:50:26.297 回答