我现在遇到了一个MSDTC事务超时的问题。由于历史原因,我们仍然有很多旧代码通过C++ ODBC运行数据库操作,并且默认情况下连接被升级为MSDTC。问题是当我尝试执行一个需要超过1分钟的长时间操作时,事务会被MSDTC自动处理掉。我发现可以通过组件服务管理工具更改此值,但我能否以编程方式设置此超时值?如有参考资料将不胜感激,谢谢。
我叫Tony,是微软支持团队的分布式事务小组成员。我已经阅读了您的帖子,并相信我理解了您所要求的内容。以下是我编写的代码示例,用于在组件级别进行更改。希望这可以帮助您:
//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();