1

別のサービスからデータを取得し、トランザクションを通じてデータベースに保存する ASP.NET WCF Web サービスがあります。つまり、すべてのデータがデータベースに保存される (コミット) か、何も保存されない (ロールバック) かのいずれかです。

データベースにデータを保存するプロセスに新しい段階を追加する必要があります。その段階では、トランザクションを使用して同じデータベースに接続する VB6 dll の関数を呼び出す必要があります。それは可能ですか?

VB6 関数を呼び出すために使用される .NET コードは次のとおりです。

object oMissing = System.Reflection.Missing.Value;
ADODB.Recordset rsKR = new ADODB.Recordset();
rsKR.Fields.Append("F1", ADODB.DataTypeEnum.adVarChar, 10, ADODB.FieldAttributeEnum.adFldFixed, null);
rsKR.Fields.Append("F2", ADODB.DataTypeEnum.adVarChar, 10, ADODB.FieldAttributeEnum.adFldFixed, null);

rsKR.Open(oMissing, oMissing, ADODB.CursorTypeEnum.adOpenStatic,    ADODB.LockTypeEnum.adLockOptimistic, -1);
rsKR.AddNew(oMissing, oMissing);

rsKR.Fields["F1"].Value = someObject.Id;
rsKR.Fields["F2"].Value = someObject.Name;

rsKR.Update(oMissing, oMissing);
rsKR.MoveFirst();

VB6Project.ClassAPI objVBAPI = new VB6Project.ClassAPI();
objVBAPI.InsertIntoDBFunction(rsKR);

前もって感謝します..

4

1 に答える 1

1

必要なことは、.NetTransactionScopeオブジェクトを使用して、例外が発生した場合にロールバックするすべての操作をラップすることです。また、VB6 コンポーネントが COM+ サービスで実行され、トランザクションが有効になっていることを確認する必要があります。

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required,
        new TransactionOptions(), EnterpriseServicesInteropOption.Full))
{
    dotNetDatabaseOperations(); //call whatever .net code here
    comProxy.comMethod(); //call to your VB6 component with interop wrapper

    scope.Complete();
} //if any exception happens in either .net or COM,
  //entire transaction will be rolled back here
于 2012-07-24T14:25:05.350 に答える