天天看點

MSDTC Service的通路權限

最近用ASP.NET做的CRM系統,BLL采用了TransactionScope來處理事務。是以,引發了一些關于TransactionScope的錯誤,是以在此總結一下錯誤類型和解決辦法。

異常一、

1、異常資訊如下:

 異常資訊為: 已禁用對分布式事務管理器(MSDTC)的網絡通路。請使用元件服務管理工具啟用 DTC 以便在 MSDTC 安全配置中進行網絡通路。

---- Stack Trace ----

   at System.Transactions.Oletx.OletxTransactionManager.ProxyException(COMException comException)

       (dll file): Native Code offset:184041

   at System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken)

       (dll file): Native Code offset:293

   at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx)

       (dll file): Native Code offset:78

   at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx)

       (dll file): Native Code offset:177

   at System.Transactions.EnlistableStates.Promote(InternalTransaction tx)

       (dll file): Native Code offset:15

   at System.Transactions.Transaction.Promote()

       (dll file): Native Code offset:61

   at System.Transactions.TransactionInterop.ConvertToOletxTransaction(Transaction transaction)

       (dll file): Native Code offset:46

   at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)

       (dll file): Native Code offset:193

   at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)

       (dll file): Native Code offset:35

   at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)

       (dll file): Native Code offset:450

   at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)

       (dll file): Native Code offset:4846418

   at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)

       (dll file): Native Code offset:4846477

   at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)

       (dll file): Native Code offset:33

   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)

       (dll file): Native Code offset:1286

   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

       (dll file): Native Code offset:65

   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

       (dll file): Native Code offset:117

   at System.Data.SqlClient.SqlConnection.Open()

       (dll file): Native Code offset:122

2、原因分析:

      這個異常的原因是因為MSDTC設定不正确引起的。

3、解決辦法:

     3.1 檢查防火牆

      如果防火牆是關的,那就不用再設定了。如果防火牆是開的,那麼確定msdtc.exe是在它的例外裡,一般這個程式是在C:\Windows\System32 \msdtc.exe這個角落。有時候你會發現在防火牆的例外裡添加了msdtc,還是不行,那有可能是跟一個端口有關系,即135端口,這是個RPC端口,在出錯的時候,可以嘗試将該端口也添加到防火牆的例外裡。

     3.2 資料庫打更新檔

     如果資料庫伺服器是sql2000,那麼確定已經打了sp4更新檔。

     如果資料庫是sql2005,那麼最好把sq2 更新檔打上。

     3.3 “管理工具”-“元件服務”-“計算機”-“我的電腦”,右鍵“我的電腦”,選擇“屬性”-“MSDTC”-“安全配置”,參照如下設定:

MSDTC Service的通路權限

      3.4 “管理工具”-“元件服務”-“計算機”-“我的電腦”,右鍵“我的電腦”,選擇“屬性”-“COM安全”-“安全配置”,編輯[通路權限]和[啟動和激活權限]的預設值,将network service賬号設定為擁有所有權限,參照如下設定:

MSDTC Service的通路權限

異常二、

1、異常資訊如下:

異常資訊為: 拒絕通路。 (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))。

---- Stack Trace ----

   at System.Transactions.Oletx.IDtcProxyShimFactory.ConnectToProxy(String nodeName, Guid resourceManagerIdentifier, IntPtr managedIdentifier, Boolean& nodeNameMatches, UInt32& whereaboutsSize, CoTaskMemHandle& whereaboutsBuffer, IResourceManagerShim& resourceManagerShim)

       (dll file): Native Code offset:0

   at System.Transactions.Oletx.DtcTransactionManager.Initialize()

       (dll file): Native Code offset:178

   at System.Transactions.Oletx.DtcTransactionManager.get_ProxyShimFactory()

       (dll file): Native Code offset:71

   at System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken)

       (dll file): Native Code offset:180

   at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx)

       (dll file): Native Code offset:84

   at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx)

       (dll file): Native Code offset:190

   at System.Transactions.EnlistableStates.Promote(InternalTransaction tx)

       (dll file): Native Code offset:18

   at System.Transactions.Transaction.Promote()

       (dll file): Native Code offset:69

   at System.Transactions.TransactionInterop.ConvertToOletxTransaction(Transaction transaction)

       (dll file): Native Code offset:46

   at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)

       (dll file): Native Code offset:193

   at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)

       (dll file): Native Code offset:20

   at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)

       (dll file): Native Code offset:463

   at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)

       (dll file): Native Code offset:133

   at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)

       (dll file): Native Code offset:5004909

   at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)

       (dll file): Native Code offset:36

   at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)

       (dll file): Native Code offset:1211

   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

       (dll file): Native Code offset:108

   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

       (dll file): Native Code offset:126

   at System.Data.SqlClient.SqlConnection.Open()

       (dll file): Native Code offset:125

   at FengYun.FYCRM.DBUtility.DbHelperSQL.PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, String cmdText, SqlParameter[] cmdParms)

       (dll file): Native Code offset:92

   at FengYun.FYCRM.DBUtility.DbHelperSQL.ExecuteSql(String SQLString, SqlParameter[] cmdParms)

       (dll file): Native Code offset:164

   at FengYun.FYCRM.DAL.RoleOfUserDAL.Add(RoleOfUserInfo model)

       (dll file): Native Code offset:1191

   at FengYun.FYCRM.BLL.UserInfoBLL.Add(UserInfo model)

       (dll file): Native Code offset:791

   at FengYun.FYCRM.WebUI.SystemManager.UserAdd.btnSave_Click(Object sender, EventArgs e)

       (dll file): Native Code offset:3159

2、原因分析:

     首先, 通過上述StackTrace可以确認,問題還是出在DTC。

     通過一些關鍵字Google了一下,原來這個問題是因為MSDTC對Authenticated Users的權限設定成(A;;CR;;;AU),而它正确地設定應該是(A;;CCLCSWRPLOCRRC;;;AU),權限解釋可以參照ACE Strings。

3、解決辦法:

     3.1 如何檢視和設定MSDTC的權限呢,首先,在DOS視窗鍵入“sc sdshow msdtc”,查詢MSDTC現在的權限設定,如下圖:

MSDTC Service的通路權限

     3.2 從上圖可以看出,這台伺服器确實将Authenticated Users的權限設定成(A;;CR;;;AU),我們隻需要将(A;;CR;;;AU)修改為(A;;CCLCSWRPLOCRRC;;;AU),就可以解決問題,如下圖:

MSDTC Service的通路權限

     3.3 DOS視窗下,“IISRESET”重新開機IIS。