如何亚音速柄连接处?亚音速

2023-09-03 01:40:48 作者:残留在记忆的最深处

在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不打烊连接

  

MySql.Data.MySqlClient.MySqlException:   错误连接:超时过期。该   超时时间已过之前   从池中获取一个连接。   出现这种情况可能是因为所有   池连接使用,最大   池大小共识。生成:星期二,   2009年5时26分05秒格林尼治标准​​时间8月11日   System.Web.HttpUnhandledException:   类型的异常   System.Web.HttpUnhandledException   被抛出。 --->   MySql.Data.MySqlClient.MySqlException:   错误连接:超时过期。   超时时间已过之前   从池中获取一个连接。   出现这种情况可能是因为所有   池连接使用,最大   池大小共识。在   MySql.Data.MySqlClient.MySqlPool.GetConnection()   在   MySql.Data.MySqlClient.MySqlConnection.Open()   在   SubSonic.MySqlDataProvider.CreateConnection(字符串   newConnectionString)在   SubSonic.MySqlDataProvider.CreateConnection()   在   SubSonic.AutomaticConnectionScope..ctor(的DataProvider   提供商)在   SubSonic.MySqlDataProvider.GetReader(QueryCommand   QRY)在   SubSonic.DataService.GetReader(QueryCommand   CMD)的   SubSonic.ReadOnlyRecord`1.LoadByParam(字符串   COLUMNNAME,对象paramValue)

我的连接字符串如下:

 <的ConnectionStrings>
    <添加名称=XX的connectionString =数据源= xx.net;端口= 3306;数据库=数据库; UID = dbuid; PWD = XX;池= TRUE;最大池大小= 12;闵池大小= 2;连接生存期= 60/>
  < /的ConnectionStrings>
 
中国评论新闻 美B1轰炸机发射新型远程反舰导弹测试获成功

解决方案

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

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

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

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

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

MySql.Data.MySqlClient.MySqlException: error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Generated: Tue, 11 Aug 2009 05:26:05 GMT System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> MySql.Data.MySqlClient.MySqlException: error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at SubSonic.MySqlDataProvider.CreateConnection(String newConnectionString) at SubSonic.MySqlDataProvider.CreateConnection() at SubSonic.AutomaticConnectionScope..ctor(DataProvider provider) at SubSonic.MySqlDataProvider.GetReader(QueryCommand qry) at SubSonic.DataService.GetReader(QueryCommand cmd) at SubSonic.ReadOnlyRecord`1.LoadByParam(String columnName, Object paramValue)

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.