We have a service that can work with a SQL Server or Oracle back end. We just started to add messaging capability to allow our service to communicate with an Oracle-only application and decided to go with NServiceBus. It was decided to place the NServiceBus subscriptions/queue/etc. on the application's database, so NServiceBus is always using Oracle.
When the service is used with a SQL Server back end, everything works great. But when we try to use the service with an Oracle back end (a completely separate database from the one used by the application & NServiceBus, often on a different server) we get exceptions.
Exception details:
- Exception text: "Connection is already part of a local or a distributed transaction" or sometimes "Unable to enlist in a distributed transaction" (a minimal VM test environment instead got "Unable to load OraMTS")
- the exception occurs when our database layer calls
connection.Open()
- the connection's connection string is standard
Data Source=foo;User Id=bar;Password=baz
- the service is using the unmanaged Oracle provider
- the service uses a decorator to connect when it starts handling a message then disconnect afterwards; removing the decorator and instead having the service connect when it starts (before setting up NServiceBus) solves the problem but means that if anything happens to that connection the service has to be restarted
The exception text makes us think the connection is trying to join NServiceBus' TransactionScope. Is that correct? If so, is there some option we can add to the connection string or configure on the connection itself to have it avoid joining the ambient TransactionScope?
Note that we use BeginTransaction in our code; we're aware that it doesn't play nice with TransactionScope but we've never had TransactionScope in our code before and don't want to be in a TransactionScope, and in any case the exceptions we're getting are happening before we even get to the BeginTransaction call.
TransactionScope
and not have it enlist. But it depends on what you're doing, and I don't understand 100% what it is you're trying to achieve, after the last comment. – Dennis van der Stelt