2011-04-02 97 views
0

我刚将NHibernate应用程序从SQL Server迁移到MySql。所有似乎都很好,除了我得到间歇性TimeoutExceptions。我可以通过MySql找到关于此超时的很多信息,甚至可以通过Hibernate + MySql + C3PO(不管是什么)超时。但没有关于如何调整NHib来阻止这个问题。你知道吗?NHibernate + MySql间歇性TimeoutException

这里是堆栈跟踪:

NHibernate.TransactionException: Begin failed with SQL exception ---> System.TimeoutException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ---> System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 
    at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    --- End of inner exception stack trace --- 
    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) 
    at MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
    --- End of inner exception stack trace --- 
    at MyNetworkStream.HandleOrRethrowException(Exception e) 
    at MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
    at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
    at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count) 
    at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) 
    at MySql.Data.MySqlClient.MySqlStream.LoadPacket() 
    at MySql.Data.MySqlClient.MySqlStream.ReadPacket() 
    at MySql.Data.MySqlClient.NativeDriver.ReadOk(Boolean read) 
    at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName) 
    at MySql.Data.MySqlClient.Driver.SetDatabase(String dbName) 
    at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String databaseName) 
    at MySql.Data.MySqlClient.MySqlConnection.Open() 
    at NHibernate.Connection.DriverConnectionProvider.GetConnection() 
    at NHibernate.AdoNet.ConnectionManager.GetConnection() 
    at NHibernate.Impl.SessionImpl.get_Connection() 
    at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel) 
    --- End of inner exception stack trace --- 
    at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel isolationLevel) 
    at NHibernate.Transaction.AdoTransaction.Begin() 
    at NHibernate.AdoNet.ConnectionManager.BeginTransaction() 
    at NHibernate.Impl.SessionImpl.BeginTransaction() 
+0

现在,你可以把一个定时器做一些伪选择,以避免超时? – Tony 2011-04-02 01:38:35

+0

蒂姆你解决这个问题,因为我想知道这越来越多... – Rippo 2011-04-12 15:06:16

回答

0

我在Rackspace的云上运行NHibernate的MySQL数据库。由于睡眠导致连接处于半开状态,因此我发现我得到了超时。最终,我的连接耗尽,我的网站超时。

最后我在连接字符串中加入了Pooling=false;。我不确定这是否是最终解决方案,但它已经阻止了我的问题。

您可以检查通过在MySQL使用编辑器睡觉show processlist连接...

+0

谢谢。哎呀!池=假?你是否担心这会对性能造成影响? – 2011-04-06 04:15:31

+0

最有可能的是,它取决于用例;但是我认为在汇集代码中存在一个错误,它将连接标记为“正在休眠”,但不允许它们被唤醒,因此最终会导致连接中断。就像我说的,这不是最终的解决方案,但至少现在对我来说这是一个解决方法。 – Rippo 2011-04-06 06:46:18

+0

蒂姆看看这个http://stackoverflow.com/questions/5567097/using-mysqlconnection-in-c-does-not-close-properly – Rippo 2011-04-12 15:08:20