Managed and immutable code that updates the database in one transaction?

Inside C #, I have OracleConnection, which updates the database and a link to the outdated VB6 DLL that C # calls to update the database (inside the DLL, the ADODB.Connection object is used).

I need to wrap them both in one big transaction so that both managed and unmanaged updates are rolled back or performed together.

I tried to switch the C # class so that it inherited from System.EnterpriseServices.ServicedComponent and was decorated with [Transaction (TransactionOption.Required)], and then using [AutoComplete] on a method that runs the calling sequence, which eventually ends up in Call OracleConnection DLL and VB6.

Like this:

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 +, #, !

, , , , !

Google .

!

+3
1

, , .

, , :

  • ​​ ComVisible.
  • [assembly: System.EnterpriseServices.ApplicationName( "blahblah" )]... blahblah COM +.
  • COM + regsvcs.exe. , , . , COM.
  • OracleConnection.EnlistDistributedTransaction, ContextUtil.Transaction( ) :

    connection.EnlistDistributedTransaction((ITransaction) ContextUtil.Transaction);

COM + " ". !

, VS2010, DoStuffTransactionally, .

, .

, , , VB6, DoStuffTransactionally, COM- VB6 COM +, . VB6 Oracle, , VB6, DistribTX = 1 PROMOTABLE TRANSACTION = PROMOTABLE. .

Yay!

, , . , , Release. :

DisconnectedContext was detected
Message: Context 0x4452b0' is disconnected.  Releasing the interfaces from the current context (context 0x444fd0). This may cause corruption or data loss. To avoid this problem, please ensure that all contexts/apartments stay alive until the application is completely done with the RuntimeCallableWrappers that represent COM components that live inside them.

, , - .

+3

Source: https://habr.com/ru/post/1786485/