Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enlisting in Ambient transactions is not supported using TransactionScope in asp.net core 2 app

When opening sql connection inside TransactionScope its giving "Enlisting in Ambient transactions is not supported" error. I am using ado.net in asp.net core 2 app.

        using (var ts = new TransactionScope())
        {
            try
            {
                Connection.Open();
                repository.Insert(entity);                    
                ts.Complete();
            }

            catch (Exception ex)
            {
                ts.Dispose();
            }
            finally
            {
                Connection.Close();
            }
        }
like image 701
shak imran Avatar asked Jan 29 '23 23:01

shak imran


1 Answers

If you encounter this problem when using .Net Standard, you can add a recent reference to System.Data.SqlClient and this problem will go away.

like image 151
randomsolutions Avatar answered Jan 31 '23 12:01

randomsolutions