MSDTC事务超时问题

时间:2011-09-27 03:00:46

标签: transactions timeout msdtc

我现在面临MSDTC交易超时问题。 由于历史原因,我们仍然有许多遗留代码通过C ++ ODBC运行数据库操作,默认情况下连接会升级到MSDTC。 问题是当我尝试执行一个耗时超过1分钟的冗长操作时,事务将由MSDTC自动处理,我发现可以通过组件服务管理工具更改此值, 但是,我可以通过编程方式设置此超时值吗?

任何参考将被提前感谢。

1 个答案:

答案 0 :(得分: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();