【问题标题】:Subsonic race condition detected each new DB connection亚音速竞争条件检测到每个新的数据库连接
【发布时间】:2017-12-07 12:01:33
【问题描述】:

我很难调试服务。

我将首先解释我正在运行的场景。 我使用他们的服务导入、生成报告和导出数据获得了 9 个数据库。 它们都运行了一两天,但是在亚音速开始在有新连接到数据库时给出异常之后,所有异常都是相似的,只需更改数据库操作,有一个例子:

Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.
   at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffsetBytes, Array dst, Int32 dstOffsetBytes, Int32 byteCount)
   at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
   at System.IO.TextWriter.WriteLine(String value)
   at System.IO.TextWriter.WriteLine(String format, Object arg0)
   at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
   at SubSonic.DataProviders.DbDataProvider.ExecuteReader(QueryCommand qry) in C:\[path]\SubSonic.Core\DataProviders\DbDataProvider.cs:line 112
   at SubSonic.Linq.Structure.DbQueryProvider.Execute[T](QueryCommand`1 query, Object[] paramValues) in C:\[path]\SubSonic.Core\Linq\Structure\DbQueryProvider.cs:line 280
   at lambda_method(Closure )
   at SubSonic.Linq.Structure.DbQueryProvider.Execute(Expression expression) in C:\[path]\SubSonic.Core\Linq\Structure\DbQueryProvider.cs:line 131
   at SubSonic.Linq.Structure.QueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) in C:\[path]\SubSonic.Core\Linq\Structure\QueryProvider.cs:line 50
   at SubSonic.Linq.Structure.Query`1.GetEnumerator() in C:\[path]\SubSonic.Core\Linq\Structure\Query.cs:line 85
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at [namespace].ReportManager.GetAllPending() in [path]\ReportManager.cs:line 193
   at [namespace].ReportsServiceHandler.Run() in C:\[path]\ReportsServiceHandler.cs:line 137

到目前为止,我唯一的解决方案是重置服务,但我还没有发现可能导致此问题的原因。我尝试在本地环境中调试它,但我无法做到。

有人知道亚音速是否存在错误,或者我如何在服务中找到问题?

提前感谢您的帮助。

【问题讨论】:

    标签: c# subsonic3


    【解决方案1】:

    subsonics3 还给你阅读器,你可以按照以下方式处理它

    Query qry = Product.CreateQuery().WHERE("ListPrice > 50.00")
                .AND("Class = L").AND("Color = Yellow");
    using(IDataReader rdr = qry.ExecuteReader())
    {
     while (rdr.Read()) {
       Console.WriteLine(rdr[Product.Columns.Name].ToString());
     }
    }
    

    使用(SqlDataReader reader = command.ExecuteReader()) { ...做你的事... }


    我认为您需要通过使用using 正确处理您的连接,因为您之前使用的连接可能仍然打开即未关闭。

    using(var connection = new Connection())
    {
    }
    

    上面的代码处理你的连接。或者如果它不存在,我建议使用Dispose Pattern 并在使用后处理连接对象。

    【讨论】:

    • 问题是连接是亚音速的,例如:return Repository.Single(x => x.CompanyID == org && x.ServiceID == service);跨度>
    • @JoãoSilva - 那么我认为您可以控制创建对象并处理它,因为我不确定在当前库中如何处理连接...
    • @JoãoSilva - 你可以这样做使用(SqlDataReader reader = command.ExecuteReader()) { ... 做你的事情... }
    • @JoãoSilva - 更新的答案请检查...并让我知道您正在使用哪个数据库
    • 所以,你的意思是我应该只在 using 中调用 subsonic 以便它可以处理连接?
    猜你喜欢
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多