在C#中,我有一個更新的DB一個OracleConnection,並且其中C#調用到更新DB遺留VB6 DLL的引用(DLL中,它使用ADODB.Connection對象)。在一個事務中更新數據庫的託管代碼和無代碼代碼?
我需要包裝他們倆在一個大的交易,因此,無論是託管和非託管更新回滾或提交在一起。
我試着切換C#類,使它從System.EnterpriseServices.ServicedComponent繼承,並用[Transaction(TransactionOption.Required)]修飾,然後在啓動調用序列的方法上使用[AutoComplete],最終命中OracleConnection和VB6 DLL調用。
像這樣:
using System.EnterpriseServices;
{
[Transaction(TransactionOption.Required)]
public class MyClassTx: ServicedComponent
{
private MyClass1 _myClass1;
public MyClassTx()
{
}
// This method automatically commits the transaction if it succeeds.
[AutoComplete]
public void DoStuffTransactionally()
{
// Calls into different objects, doing some work that I'd like to have
// a big transaction around.
_MyClass1 = new MyClass1()
_MyClass1.DoSomeStuff();
}
}
}
然而,當我的測試工具試圖實例MyClassTx,我得到這個錯誤:
{System.EnterpriseServices.RegistrationException: Invalid ServicedComponent-derived classes were found in the assembly.
(Classes must be public, concrete, have a public default constructor, and meet all other ComVisibility requirements)
我已經驗證了我的課是公共的,具體的,具有一個無參數的構造函數。不過,它不會實例化。
我需要強力型我組裝,放入一個COM +組件之前,我甚至能調試嗎?我會假設,使用VS2010,我可以進入ServicedComponent繼承代碼。
它已經8年,因爲我已經使用COM +,這是我第一次嘗試得到它在C#中工作,所以任何幫助,將不勝感激!
而且,如果我在這裏標題下一個愚蠢的路徑,並還有一個更簡單的方式來獲得我的管理和unamanaged代碼到相同的事務,請賜教!
幾個小時與谷歌並沒有太大的幫助。
非常感謝!