如何亚音速柄连接处

如何亚音速柄连接处

本文介绍了如何亚音速柄连接处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NHibernate的,你通过在一个的BeginRequest和关闭创建它启动一个会话EndRequest

 公共类全球:System.Web.HttpApplication
{
    公共静态ISessionFactory的SessionFactory = CreateSessionFactory();

    受保护的静态ISessionFactory CreateSessionFactory()
    {
    返回新配置()
    .Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,hibernate.cfg.xml中))
    .BuildSessionFactory();
    }

    公共静态的ISession CurrentSession
    {
    {返回(ISession的)HttpContext.Current.Items [current.session]; }
    集合{HttpContext.Current.Items [current.session] =值; }
    }

    保护无效环球()
    {
    的BeginRequest + =委托
    {
    CurrentSession = SessionFactory.OpenSession();
    };
    EndRequest + =委托
    {
    如果(CurrentSession!= NULL)
    CurrentSession.Dispose();
    };
    }
}
 

什么是等值的亚音速?

我理解的方式,NHibernate的会收endrequest所有连接。

原因:当故障排除一些旧的code在亚音速项目中,我得到了很多的MySQL超时,这表明code不打烊连接

我的连接字符串如下:

 <的ConnectionStrings>
    <添加名称=XX的connectionString =数据源= xx.net;端口= 3306;数据库=数据库; UID = dbuid; PWD = XX;池= TRUE;最大池大小= 12;闵池大小= 2;连接生存期= 60/>
  < /的ConnectionStrings>
 

解决方案

它总是一次出手,除非你专门包了SharedDbConnectionScope你的东西。特别是在测试的MySQL在Windows上 - - 我以前看到这一点。而问题是,MySQL的驱动程序有错误,不关闭连接

我能够创建一个控制台应用程序,一个基本的阅读器,然后遍历它瑞普这一点 - 咣当。的ConnectionPool错误。

没有太多的答案,我知道,但有什么可以做亚

In Nhibernate you start a session by creating it during a BeginRequest and close atEndRequest

public class Global: System.Web.HttpApplication
{
    public static ISessionFactory SessionFactory = CreateSessionFactory();

    protected static ISessionFactory CreateSessionFactory()
    {
    	return new Configuration()
    		.Configure(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "hibernate.cfg.xml"))
    		.BuildSessionFactory();
    }

    public static ISession CurrentSession
    {
    	get{ return (ISession)HttpContext.Current.Items["current.session"]; }
    	set { HttpContext.Current.Items["current.session"] = value; }
    }

    protected void Global()
    {
    	BeginRequest += delegate
    	{
    		CurrentSession = SessionFactory.OpenSession();
    	};
    	EndRequest += delegate
    	{
    		if(CurrentSession != null)
    			CurrentSession.Dispose();
    	};
    }
}

What’s the equivalent in Subsonic?

The way I understand, Nhibernate will close all the connections at endrequest.

Reason: While trouble shooting some legacy code in a Subsonic project I get a lot of MySQL timeouts,suggesting that the code is not closing the connections

My connection string is as follows

<connectionStrings>
    <add name="xx" connectionString="Data Source=xx.net; Port=3306; Database=db; UID=dbuid; PWD=xx;Pooling=true;Max Pool Size=12;Min Pool Size=2;Connection Lifetime=60" />
  </connectionStrings>
解决方案

It's always a one-time shot unless you specifically wrap your stuff with a "SharedDbConnectionScope". I've seen this before - specifically while testing MySQL on windows - and the problem is that the MySQL driver is buggy and doesn't shut off connections.

I was able to repro this by creating a console app and a basic reader then looping over it - bam. ConnectionPool errors.

Not much of an answer, I know, but what can ya do.

这篇关于如何亚音速柄连接处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 01:33