我有一個MS SQL 2008數據庫,通過LINQ訪問數據更新/回溯。使用實體框架併發訪問數據庫== EntityException
我的linq由Percall實例化模式下的WCF服務訪問,適用於繁重的應用程序。此應用程序有幾個線程可以調用服務,並且多個應用程序正在同一時間運行。
我常常已經有些EntityException發生:
System.Data.EntityException被抓獲 消息=在啓動提供商連接上一個交易發生錯誤。詳情請參閱內部例外。 源= System.Data.Entity的 堆棧跟蹤: 在System.Data.EntityClient.EntityConnection.BeginDbTransaction(的IsolationLevel的IsolationLevel) 在System.Data.EntityClient.EntityConnection.BeginTransaction() 在System.Data.Objects.ObjectContext.SaveChanges (SaveOptions選項) at D:\ Workspace \ XYZWASDF \ DataServer \ DataServer.cs中的Infoteam.GfK.TOMServer.DataServer.DataServer.SaveChanges():第123行 InnerException:System.Data.SqlClient.SqlException Message = Une nouvelle交易不需要任何線索,只需在線交易即可。 源= .net SqlClient數據提供 錯誤碼= -2146232060 類= 16 LineNumber上= 1 總數= 3988 過程= 「」 服務器= IFT-srv114 狀態= 1 堆棧跟蹤: 在System.Data.SqlClient的.SqlConnection.OnError(SqlException異常,Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException異常,Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient。 TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHand Lr,TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte [] buffer,TransactionManagerRequestType request,String transactionName,TransactionManagerIsolationLevel isoLevel,Int32 timeout,SqlInternalTransaction transaction,TdsParserStateObject stateObj,Boolean isDelegateControlRequest) at System.Data.SqlClient .SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest,字符串transactionName,異的IsolationLevel,SqlInternalTransaction internalTransaction,布爾isDelegateControlRequest) 在System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest,字符串名稱,異的IsolationLevel,SqlInternalTransaction internalTransaction,布爾isDelegateControlRequest) 在系統.Data.SqlClient.SqlInternalConnection.BeginSqlTransac灰(異的IsolationLevel,字符串transactionName) 在System.Data.SqlClient.SqlInternalConnection.BeginTransaction(IsolationLevel將異) 在System.Data.SqlClient.SqlConnection.BeginDbTransaction(的IsolationLevel的IsolationLevel) 在System.Data.Common.DbConnection.BeginTransaction(的IsolationLevel的IsolationLevel) 在System.Data.EntityClient.EntityConnection.BeginDbTransaction(的IsolationLevel的IsolationLevel) 的InnerException:
(對不起這不是很可讀)。 (內部異常的消息意味着「不允許新的事務,因爲會話中有其他線程在運行。「
我檢查,我不是在一個循環中,它是完全隨機的,當它使這個例外,並且我沒有關於如何避免這種想法
任何幫助將是非常讚賞: )
謝謝
編輯:!這裏是在那裏我得到這個例外SOMETIMES
//My DataServer method, which is a singleton
[MethodImpl(MethodImplOptions.Synchronized)]
public void SaveChanges()
{
lock (_lockObject)
{
try
{
_context.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
_changeListener.ManageIDAfterInsert();
}
catch (Exception ex)
{
Logger.Instance.Error("[DataServer:SaveChanges] Got an error when trying to save an object", ex);
//HERE I've this error
}
}
}
//One example where I can have exception sometimes, this is called through a WCF service, so I have a method which attach the object and then save it
private OrderStatus AddOrderStatus(OrderStatus orderStatus)
{
DataServer.DataServer.Instance.InsertOrUpdateDetachedObject(orderStatus);
return orderStatus;
}
您能顯示導致此錯誤的代碼嗎? – 2011-02-28 15:10:22