using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
SqlCommand cmd = new SqlCommand("ProcedureName", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Name", "upendra");
cmd.Parameters.AddWithValue("EmailId", "[email protected]");
cmd.Parameters.AddWithValue("MobileNumber", "384747848");
con.Open();
cmd.ExecuteNonQuery();
scope.Complete();
}
Error: Enlisting in Ambient transactions is not supported
This was implemented in https://github.com/dotnet/corefx/pull/22059.
I am getting exception in .net core 2.0 and System.Data.SqlClient v4.4.0
That change is not in .NET Core 2.0. It's in the master branch for the next release.
It's on daily builds?
Yes.
Maybe i'm getting wrong, but https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.Data.SqlClient last update was 22 days ago.
@grandchamp ignore the "preview2" packages. This was a temporary glitch. The latest at the moment is https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.Data.SqlClient/4.5.0-preview1-25729-02
Fixed with https://github.com/dotnet/corefx/pull/22059
There's an interesting point here.
On System.Data.SqlClient v4.3.0 opening an SqlConnection inside TransactionScope
or with set Transaction.Current
works. Transaction isn't distributed of cause, but SqlClient doesn't throw. It works in the same way as without TransactionScope
.
On the contrary on System.Data.SqlClient v4.4.0 opening an SqlConnection in the same conditions throws System.NotSupportedException: "Enlisting in Ambient transactions is not supported".
So code ported from netfx worked on 4.3 but starts failing on 4.4.
Any update on when 4.5 will be available for general consumption? Transaction management is becoming a blocker for us.
Is there any idea about workaround? Any help is higly appreciated, it blocks my work too :(
@stu-mck I solved this issue in my project, here is my workaround for this problem - https://stackoverflow.com/questions/47421371/dapper-is-throwing-system-data-sqlclient-sqlconnection-exception-after-upgrading/48273860#48273860
based on @evil-shrike comment
I'm using linq2db in my project, so I got rid of references on EntityFramework and downgraded version of System.Data.SqlClient to 4.3
For Hangfire, wich depends on Dapper it worked too
Please reopen this issue, it's a blocker over here too and there's no satisfactory workaround afaik.
We have the same issue. We are starting a class library targeting .NET Standard 2.0. We faced the "Ambient transactions is not supported", so we tried the workaround of downgrade the version of System.Data.SqlClient to 4.3.x, but this cause the following build error:
Folder\Class.cs(9,75): error CS0433: The type 'SqlDbType' exists in both 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [C:\Path\MyProject.csproj]
We tried with several versions of System.Data.SqlClient with no success. According to the official documentation CS0433 could be solved with the -reference option of csc.exe, but I don't know how (if even possible) to pass such parameters from "dotnet build".
Any clue? Please help, because I cannot wait to Q2 2018 for the patch, and I would not like to use the other workaround proposed: use explicit transaction model.
Many thanks in advance.
@mikeloguay I tried all the suggested workarounds and none of them worked.
In the end I had to use the explicit model (BeginTransaction/Commit) :(
This is still an issue. I've also tried all the workarounds suggested here with no success.
I have the same issue.
When will this be fixed? its a serious blocker for us :(
This is now supported on the 4.5 preview build of SqClient available on Nuget
thanks @saurabh500
I has this problem in .Net standart 2.0 with Dapper, thank you, i was update System.Data.Sql from 4.3 to 4.5.1 and Dapper start working)
Most helpful comment
Please reopen this issue, it's a blocker over here too and there's no satisfactory workaround afaik.