2011-09-27 120 views
3

我現在正面臨MSDTC事務超時問題。 由於歷史原因,我們仍然有大量遺留代碼通過C++ ODBC運行數據庫操作,並且默認情況下連接升級爲MSDTC。 問題是當我嘗試執行耗時超過1分鐘的冗長操作時,事務將由MSDTC自動處理,我發現可以通過組件服務管理工具 更改此值。但是,我可以設置此超時價值編程?MSDTC事務超時問題

任何參考將不勝感激,在此先感謝。

回答

6

我的名字是Tony和我在Microsoft支持部門的分佈式事務團隊工作。我已閱讀你的文章,並相信我明白你的要求。以下是我編寫的用於在組件級別進行更改的代碼示例。我希望這可以幫助你:

//Connect to the machine 
COMAdmin.COMAdminCatalog m_objAdmin1 = new COMAdmin.COMAdminCatalog(); 
m_objAdmin1.Connect(System.Environment.MachineName.ToString()); 

//Get a list of COM+ Applications 
COMAdmin.COMAdminCatalogCollection objApplications = (COMAdmin.COMAdminCatalogCollection)m_objAdmin1.GetCollection("Applications"); 
objApplications.Populate(); 
COMAdmin.COMAdminCatalogObject appToFind = null; 

//Find the application you want to change 
for (int i = 0; i < objApplications.Count; i++) 
{ 
    appToFind = (COMAdmin.COMAdminCatalogObject)objApplications.get_Item(i); 

    if (appToFind.Name.ToString() == "MSTEST") 
    { 
     break; 
    } 
} 


//Now find the component in the application you wish to change 
COMAdmin.COMAdminCatalogCollection objComponents = (COMAdmin.COMAdminCatalogCollection)objApplications.GetCollection("Components", appToFind.Key); 
objComponents.Populate(); 
COMAdmin.COMAdminCatalogObject ComponentsToFind = null; 

for (int i = 0; i < objComponents.Count; i++) 
{ 
    ComponentsToFind = (COMAdmin.COMAdminCatalogObject)objComponents.get_Item(i); 

    if (ComponentsToFind.Name.ToString() == "tdevere_vb6_com.Tdevere") 
    { 
     break; 
    } 
} 

//Set the Transaction support option 
//Enable the overide option 
//Set the new value for the time out option 
COMAdmin.COMAdminTransactionOptions temp = (COMAdmin.COMAdminTransactionOptions)ComponentsToFind.get_Value("Transaction"); 
ComponentsToFind.set_Value("Transaction", COMAdmin.COMAdminTransactionOptions.COMAdminTransactionRequiresNew); 
ComponentsToFind.set_Value("ComponentTransactionTimeout", 120); 
ComponentsToFind.set_Value("ComponentTransactionTimeoutEnabled", true); 

//Make sure to save the changes 
objComponents.SaveChanges(); 
objApplications.SaveChanges();