runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Enlisting in Ambient transactions is not supported

Open upendra22 opened this issue 9 years ago • 21 comments

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

upendra22 avatar Sep 27 '17 14:09 upendra22

This was implemented in https://github.com/dotnet/corefx/pull/22059.

stephentoub avatar Sep 27 '17 14:09 stephentoub

I am getting exception in .net core 2.0 and System.Data.SqlClient v4.4.0

upendra22 avatar Sep 27 '17 16:09 upendra22

That change is not in .NET Core 2.0. It's in the master branch for the next release.

stephentoub avatar Sep 27 '17 16:09 stephentoub

It's on daily builds?

grandchamp avatar Sep 29 '17 17:09 grandchamp

Yes.

stephentoub avatar Sep 29 '17 17:09 stephentoub

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 avatar Sep 29 '17 17:09 grandchamp

@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

danmoseley avatar Sep 29 '17 19:09 danmoseley

Fixed with https://github.com/dotnet/corefx/pull/22059

saurabh500 avatar Nov 30 '17 18:11 saurabh500

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.

evil-shrike avatar Dec 20 '17 11:12 evil-shrike

Any update on when 4.5 will be available for general consumption? Transaction management is becoming a blocker for us.

stu-mck avatar Jan 05 '18 05:01 stu-mck

Is there any idea about workaround? Any help is higly appreciated, it blocks my work too :(

y-vasilyev avatar Jan 15 '18 07:01 y-vasilyev

@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

y-vasilyev avatar Jan 16 '18 04:01 y-vasilyev

Please reopen this issue, it's a blocker over here too and there's no satisfactory workaround afaik.

mikefayer avatar Jan 17 '18 14:01 mikefayer

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 avatar Jan 23 '18 09:01 mikeloguay

@mikeloguay I tried all the suggested workarounds and none of them worked. In the end I had to use the explicit model (BeginTransaction/Commit) :(

edaloicaro18 avatar Mar 07 '18 03:03 edaloicaro18

This is still an issue. I've also tried all the workarounds suggested here with no success.

matthewblott avatar Mar 07 '18 18:03 matthewblott

I have the same issue.

liesbethvandevenne avatar Mar 09 '18 14:03 liesbethvandevenne

When will this be fixed? its a serious blocker for us :(

jeinz11 avatar Mar 29 '18 01:03 jeinz11

This is now supported on the 4.5 preview build of SqClient available on Nuget

saurabh500 avatar Mar 29 '18 01:03 saurabh500

thanks @saurabh500

jeinz11 avatar Mar 29 '18 06:03 jeinz11