.net atomic operation with an external dll

179 views Asked by At

In my .net application, i need to use an external dll that was provided to me as "close box". I can't access or modify the dll.

I know that it has its own transaction. The problem is that when i call the dll methods i can't pass my connection/transaction to them. But my application's operations on the db must be atomic with the dll operation.

Both, my application and the dll work on the same database.

There is a way to resolve this without use the TransactionScope? And, if the answer is no, is TransactionScope at the state of the art a good solution?

UPDATE

I tried with the TransactionScope:

using (TransactionScope transactionScope = new TransactionScope())
{
    using (var connection = new OleDbConnection(DatabaseInfo.Instance.GetConnectionString(connectionStr))
    {
        var sqlQuery = "select * from TEST_TABLE";

        using (var dbCmd = new OleDbCommand(sqlQuery, connection))
        {
            connection.Open();
            var a = dbCmd.ExecuteNonQuery();
        }
    }
    transactionScope.Complete();
}

But on the connection.Open() i received this error: New transaction cannot enlist in the specified transaction coordinator.

UPDATE 2

I solved the error adding OLE DB Services = -7 (equivalent at enlist = false in SqlConnection) at the end of the connection string. In this way I disable the pooling, the enlistment, and the cursor services. But now the problem is that the transaction is committed anyway, even if the transactionScope.Complete() is not reached when an exception is thrown.

0

There are 0 answers