3

TransactionScope throwing exception. I am using ASP.NET Core with Core 3.0.

I get following issue locally on Windows: "This platform does not support distributed transactions."

I would like to sync two databases and would like to use TransactionScope to get a consistent state in both databases.

When I deploy it to Azure using AppService and Azure Sql it works fine.

Normally it should work when I check this link with .net core 3.0. https://learn.microsoft.com/de-de/dotnet/api/system.transactions.transactionscope?view=netcore-3.0

Hope somebody can help me.

using (var scope = new TransactionScope())
{

   -- database1
   using (SqlConnection connection = new SqlConnection(connectionString_DB1))
   {
      using (System.Data.SqlClient.SqlCommand cmd = connection.CreateCommand())
      {
         ....
         connection.Open();
         result = cmd.ExecuteNonQuery();
      }
   }

   --database2
   using (SqlConnection connection = new SqlConnection(connectionString_DB2))
   {
      using (System.Data.SqlClient.SqlCommand cmd = connection.CreateCommand())
      {
         ....
         connection.Open();
         result = cmd.ExecuteNonQuery();
      }
   }

   scope.Complete();
}
Maza
  • 86
  • 5
  • Does this answer your question? [Transactionscope throwing exception this platform does not support distributed transactions while opening connection object](https://stackoverflow.com/questions/56328832/transactionscope-throwing-exception-this-platform-does-not-support-distributed-t) – Alexandra Petrova Mar 31 '20 at 16:12
  • 2
    Thanks! Not really, I have already seen it and this answers does not solve my issues. I'm using .net core 3.0 and as I mentioned it's working on Azure but not locally on my Windows comupter. Microsoft says on their page thats working for it with an example. Can somebody specify why its working on Azure but not locally and will there be a solution for it? Thanks a lot for you help! – Maza Apr 01 '20 at 06:35

1 Answers1

0

Besides placing using, add Close method call after using connection.

I just had the same error using TransactionScope while clearly connecting to the same database and placing using. The majority of answers say that Dispose and Close are identical, but it seems they aren't: from what I gleaned from source code, Close method explicitly returns connection to pool, while I could not find identical code for Dispose.

Alexander Kozachenko
  • 885
  • 2
  • 13
  • 26