Is it possible to have a transaction between an on premises SQL Server instance and an Azure SQL database.
I have the following tests cases.
public class TransactionsTest
{
[Fact]
public void Test1()
{
var premisesDatabaseContext = new OnPremisesDatabaseContext();
var azureSQLDatabaseContext = new AzureSQLDatabaseContext();
using (TransactionScope scope = new TransactionScope())
{
premisesDatabaseContext.Database.Connection.Open();
azureSQLDatabaseContext.Database.Connection.Open();
scope.Complete();
}
}
[Fact]
public void Test2()
{
var premisesDatabaseContext = new OnPremisesDatabaseContext();
var azureSQLDatabaseContext = new AzureSQLDatabaseContext();
using (TransactionScope scope = new TransactionScope())
{
azureSQLDatabaseContext.Database.Connection.Open();
premisesDatabaseContext.Database.Connection.Open();
scope.Complete();
}
}
}
It seems pretty straightforward. But both tests cases fails with different errors when I open the second connection.
Here is the errors details.
// TEST 1
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation.
--->
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Transactions.Transaction.GetPromotedToken()
// TEST 2
System.Transactions.TransactionPromotionException:
There is a promotable enlistment for the transaction which has a PromoterType value that is not recognized by System.Transactions.
1c742caf-6680-40ea-9c26-6b6846079764
I want to know if it is possible to accomplish this. If it's not possible, what are the alternatives?