2011-04-02 41 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