2016-05-03 18 views
1

私はバックエンドで更新しているそれぞれの独自のトランザクションオブジェクトを持つ5つの異なるストアドプロシージャを実行しているコードを継承しました。 それらはすべて同時にコミットまたはロールバックする必要があるとして、私はトランザクションスコープオブジェクト内のすべての5つのSQLトランザクションを包み、今では、次のエラーを投げています:入れ子になったSQLトランザクションを持つTransactionScope

An exception of type 'System.Transactions.TransactionManagerCommunicationException' 
occurred in applicationname.dll but was not handled in user code 

Additional information: Network access for Distributed Transaction Manager (MSDTC) has been disabled. 
Please enable DTC for network access in the security configuration for 
MSDTC using the Component Services Administrative tool. 

これは、すぐにコードヒットとしての機能であります、それは例外をスロー:The transaction manager has disabled its support for remote/network transactions

が、私は問題を理解せずに、これらのオプションを有効にしたくない:

Protected Overridable Function GetParameters(ByRef inConnection As SqlClient.SqlConnection _ 
            , ByVal inStoredProcedureName As String _ 
            , ByVal inIncludeReturnValue As Boolean) As SqlClient.SqlParameter() 

    Return SqlHelperParameterCache.GetSpParameterSet(inConnection, inStoredProcedureName, inIncludeReturnValue) 
End Function 

この記事では、この問題を解決する方法を説明しています。トランザクションスコープ内でsqltransactionsをラップすることはできませんか、または接続が使用されているのでこの問題が発生していますか?

--update 1

当社のDBAは現在、MSDTCを有効にしているし、それは私がWCFのWebサービスを呼び出していた場合を除き、すべてのコールで動作します。それはちょうど今、私にタイムアウト例外がスローされます。

The operation has timed out 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.Net.WebException: The operation has timed out 

Source Error: 


    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

スタックトレース:2

タイムアウトはロックによって引き起こされているように見えた

[WebException: The operation has timed out] 
System.Net.HttpWebRequest.GetResponse() +8420880 
System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +234 

[TimeoutException: The HTTP request to 'http://test/testValidationService/test.svc' has exceeded the allotted timeout of 00:01:00. The time allotted to this operation may have been a portion of a longer timeout.] 

System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) +7074108 
    System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +16650152 
    System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) +388 


[TimeoutException: The request channel timed out while waiting for a reply after 00:00:59.9843749. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.] 
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +14579646 
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +622 

を更新。だから私はトランザクションスコープ内でトランザクションを持っていると私はトランザクションスコープはラッパーですが、今はトランザクションが無視されると思ったが、明らかに問題を修正したような個々のトランザクションをコミットまたはロールバックする必要があります。私が読んだことから、最後のsayはtransactionscopeになるので、個々のコミット/ロールバックは無視されますか?それは正しい?誰かがそれに光を当ててもらえますか?

+0

タイムアウトは完全に有効な場合があります。あなたのサービスで何をするには、エラーを見るときに設定されているように思われるので、1分以上かかることがありますか? –

+0

@シモン:デッドロックのために起こっていることがわかりました。前に記事を読んでから、もし私がすべての呼び出しをラップする親としてtransactionscopeを持っていれば、それ自身の個々のトランザクションを使っている子メソッドは無視されますが、そうではないようです。 – Baahubali

+1

DTCのデッドロックの診断に役立つのは難しいです.DTCのデッドロックなどでGoogleを試してみるなど、コンテキスト、設定、セキュリティなどに大きく依存するためです。また、IsolationLevel.ReadCommittedオプションを使用してTransactionScopeインスタンスを作成していることを確認してくださいSQLサーバーのデフォルトと一致する:http://stackoverflow.com/questions/11292763/why-is-system-transactions-transactionscope-default-isolationlevel-serializable) –

答えて

3

使用しているSQL Serverのバージョンはどれですか? SQL Server 2005およびそれ以前で

  1. DTCエスカレーションはできるだけ早くあなたがDBへの複数の接続を開くように行われます。

  2. エスカレーションを防止するには、トランザクション内のすべてのクエリで同じSqlConnectionオブジェクトを使用します。 SQL Server 2008および上記で

  1. 開閉接続のみの接続が一度に開いているようにエスカレートしません。
  2. ネストされたsqlconnectionsはすぐにDTCにエスカレートします。

詳細については、この質問を参照してください。 TransactionScope automatically escalating to MSDTC on some machines?

+0

SQL Server 2008 R2を使用しています。 – Baahubali

+0

dbaは指定されたオプションを有効にすることを拒否しています。セキュリティ上のリスクはありますか? – Baahubali

+0

これは、一度に1つのSQL接続しか開いていないことを確認してから、MSTDCを有効にする必要はありません。 DTCのエスカレーションを防止するためには、分散トランザクションの場合には当てはまらないので、dbaは正しいです。 –

関連する問題