今天發現正式主機上的ASP.NET 2.0程式傳回以下錯誤:
Stack Trace:
[SqlException (0x80131904): New request is not allowed to start because it should come with valid transaction descriptor.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857578
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +735190
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
   System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj) +600
   System.Data.SqlClient.SqlInternalConnectionTds.PropagateTransactionCookie(Byte[] cookie) +38
   System.Data.SqlClient.SqlInternalConnection.EnlistNull() +61
   System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx) +736046
   System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction) +38
   System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction) +30
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +1209
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.SqlClient.SqlConnection.Open() +111
   Blah.SqlDataProvider.Query(String cmdText) in C:\Documents and Settings\jeffrey\My Documents\Visual Studio 2005\Projects\Blah\SqlDataProvider.cs:472

出錯的程式只是簡單的查詢,並沒有啟動TransationScope,但由StackTrace來看,出現TdsExecuteTransactionManagerRequest等Method,很像被包在TransactionScope中的Behavior。追蹤前因後果,發現這個錯誤發生在一個包含TransactionScope的ASP.NET因Exception Rollback之後,同樣的訊息隔了幾鐘出現兩次,但期間也有其他ASP.NET成功完成資料庫存取。感覺上很像Connection Pool中有一條壞掉的Connection(由TransactionScope Rollback那條?),誰用到誰倒楣。

Google了一下,很快找到MS的KB 916002。發生的條件為ADO.NET 2 + SQL 2005,再加上

• The connection is reused from the connection pool in a distributed transaction.
Connection Pool中的Connection用在分散式交易
•  A local transaction is committed or rolled back before the connection.
連線前有本地的交易Commit或Rollback(真是語簡意賅,看不懂)
• The local transaction ends before the connection.
連線前本地交易結束(一整個深奧,無法理解)

雖然不能完全了解KB裡的描述,但就Error Message及之前發生Rollback兩點的符合,我覺得是它的機率很高。MS承認這是Bug,很不幸地,它2006/6/26才公佈,沒趕上2006/4的SQL 2005 SP1,所以得裝Hotfix修正。[2007-04-20 更正,它是.NET 2.0的Hotfix才對] 由於是上線DB,想等到週末再來安裝Hotfix,到時再跟大家報告結果。


Comments

Be the first to post a comment

Post a comment