小编Mr *_*Moo的帖子

与蜘蛛交易过程中的交易有关的各种NHibernate错误

我们有一个ASP.Net 4/MVC 3混合Web应用程序,它使用NInject 3和(Fluent)NHibernate 3.2.DB是SQL Server 2008 R2.服务器是6核28 GB Windows 2008 64位服务器.

我们的客户最近开始使用蜘蛛工具测试该网站.一旦站点遇到蜘蛛产生的负载,我们的日志开始填满异常.

我们看到来自NHibernate的各种错误,包括以下一些错误:

  • NHibernate.TransactionException:使用SQL异常提交失败---> System.Data.SqlClient.SqlException:无法执行事务操作,因为有待处理的事务处理的请求.

  • System.Data.SqlClient.SqlException(0x80131904):服务器无法恢复事务.说明:410000050f.此会话中活动的事务已由另一个会话提交或中止.

  • System.NullReferenceException:未将对象引用设置为对象的实例.在System.Data.SqlClient.SqlInternalTransaction.GetServerTransactionLevel()....

  • NHibernate.Exceptions.GenericADOException:无法执行本机批量操作查询:exec [Stats.InsertListingStatsList] @ListingStats =:ListingStats [SQL:exec [Stats.InsertListingStatsList] @ListingStats = @ p0] ---> System.Data.SqlClient. SqlException:不允许启动新请求,因为它应该带有有效的事务描述符.

仅举四个例子.所有这些都有类似的风格 - 它们似乎都与ADO.Net作为NHibernate基础的交易管理有关.

现在,我们NH实施的一些细节:

  • SessionFactory是静态的;
  • SessionFactory使用AdoNetTransactionFactory;
  • ISession在请求范围内,并存储在HttpContext.Items集合中;
  • 存储库也在请求范围内;
  • 我们现在使用config.CurrentSessionContext();
  • 每次调用我们的通用存储库都使用一个事务

以下是我们的存储库中的两种方法.

public T GetById<T>(int id)
{
    using (var t = Session.BeginTransaction())
    {
        var entity = Session.Get<T>(id);
        t.Commit();
        return entity;
    }
}

public void Add<T>(T entity)
{
    using (var t = Session.BeginTransaction())
    {
        Session.Save(entity);
        t.Commit();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题很简单:出了什么问题?是什么导致了交易之间或者我们的域名在我们的域名中解除的各种数据相关操作之间的这些明显冲突?

更新:这是我们的完整配置:

public …
Run Code Online (Sandbox Code Playgroud)

asp.net nhibernate asp.net-mvc ninject sql-server-2008

5
推荐指数
1
解决办法
2294
查看次数