Repository navigation
Closed
Description
While testing the .net core 2.1 implementation of TransactionScope I ran into the following issue.
We have a library that configures settings for DB Connections and Transaction scope (Data.Core). Other libraries call this library to execute queries using dapper.
When I execute the code without the debugger, everything runs fine. When I set a breakpoint in the unit test AND also in the method where the DB connection is opened. I then get the exception below.
Any ideas?
System.PlatformNotSupportedException
HResult=0x80131539
Message=This platform does not support distributed transactions.
Source=System.Transactions.Local
StackTrace:
at System.Transactions.Distributed.DistributedTransactionManager.GetDistributedTransactionFromTransmitterPropagationToken(Byte[] propagationToken)
at System.Transactions.TransactionInterop.GetDistributedTransactionFromTransmitterPropagationToken(Byte[] propagationToken)
at System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx)
at System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx)
at System.Transactions.EnlistableStates.Promote(InternalTransaction tx)
at System.Transactions.Transaction.Promote()
at System.Transactions.TransactionInterop.ConvertToDistributedTransaction(Transaction transaction)
at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Data.Core.DataStore.get_Connection() in D:\TestApps\Repro\Debugger.Issue\Data.Core\DataStore.cs:line 37
at Data.Core.Tests.ReproTest1.TestMethod1() in D:\TestApps\Repro\Debugger.Issue\Data.Core.Tests\ReproTest1.cs:line 14
This is the test method in Data.Core.Tests:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Data.Core.Tests
{
[TestClass]
public class ReproTest1
{
[TestMethod]
public void TestMethod1()
{
DataStore ds = new DataStore();
using (var scope = ds.BeginTransactionScope())
{
// Set breakpoint on the following line. 1 of 2 breakpoints.
var conn = ds.Connection;
// The following will never be executed in debug
// Run raw ADO.NET command in the transaction
var command = conn.CreateCommand();
command.CommandText = "DELETE FROM dbo.SomeTable";
command.ExecuteNonQuery();
}
}
}
}This is DataStore class:
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Transactions;
namespace Data.Core
{
using IsolationLevel = System.Transactions.IsolationLevel;
public class DataStore
{
public DataStore()
{
this.DatabaseConnectionString = "Data Source=.;Initial Catalog=SomeDB;Integrated Security=True";
}
/// <summary>
/// Gets or sets the database connection string used to create the database connection.
/// This cannot be null.
/// </summary>
private string DatabaseConnectionString { get; set; }
/// <summary>
/// Gets the connection.
/// </summary>
public SqlConnection Connection
{
get
{
// Set breakpoint on the following line. 2 of 2 breakpoints.
var connection = new SqlConnection(this.DatabaseConnectionString);
if (connection.State != ConnectionState.Open)
{
// This line will throw exception
connection.Open();
}
// See if we need to join an existing transaction scope
if (Transaction.Current != null)
{
((DbConnection) connection).EnlistTransaction(Transaction.Current);
}
return connection;
}
}
/// <inheritdoc />
public TransactionScope BeginTransactionScope()
{
return new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted });
}
}
}I have attached a project to reproduce the error.
Debugger.Issue.zip
[EDIT] Add C# syntax highlighting by @karelz
Reacted by Steven Rasmussen, Wes Anastasi, Vlad Pikalev, David Rettenbacher, Davood Faramarzi and Simon Cropp
Metadata
Metadata
Assignees
Labels
No labels
Activity
BrotherOdin commentedon May 10, 2018
dotnet --info
karelz commentedon May 10, 2018
Distributed transactions are not supported yet - see #16755
BrotherOdin commentedon May 10, 2018
That is part of the bug. This code should never try to elevate to use Distributed transactions. It seems to do it only if you add the breakpoints and stop during debugging.
If you just execute, there is no Distributed transaction and it works just fine.
jimcarley commentedon May 10, 2018
This looks to be an issue with System.Data, based on this part of the callstack:
at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
at System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.ProviderBase.DbConnectionPool.PrepareConnection(DbConnection owningObject, DbConnectionInternal obj, Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)at System.Data.SqlClient.SqlConnection.Open()
System.Data is asking for the "ExportCookie" for the transaction. That can only be obtained after promoting the transaction.
System.Data should be trying to do a Transaction.EnlistPromotableSinglePhase first, before asking for the Export Cookie. But if EnlistPromotableSinglePhase returns "false", that means that a call to EnlistDurable or another EnlistPromotableSinglePhase has already been made for the transaction. This could lead to System.Data trying to get the Export Cookie.
Adding label for area-System.Data.SqlClient and adding @saurabh500
karelz commentedon May 10, 2018
cc @David-Engel @keeratsingh
BrotherOdin commentedon May 28, 2018
Is this something that will be fixed as part of the 2.1 release?
keeratsingh commentedon May 29, 2018
Hi @BrotherOdin
I am unable to repro the issue using the repro code you provided in my enviornment, I have stripped down the repro you provided to a bare minimum where it uses .NET SDK Runtime Version
2.1.300-rc1-008673and SqlClient Version4.5.0-rc1.I have tried both running it via
command promptandplacing debug breakpointsusing Visual Studio, however I still cannot repro the issue.I have attached the Visual Studio solution of the minimal repro, could you kindly try the same and let me know if you see the exception in your environment ?
adhoc_gh_29633.zip
BrotherOdin commentedon May 30, 2018
I will try it and report back. Stay tuned.
BrotherOdin commentedon May 30, 2018
The one in the ZIP is using System.Data.SqlClient (4.6.0-preview1-26529-04) rather than 4.5.0-rc1 so I could not try it.
Once I update it back to 4.5.0-rc1, I am able to recreate the problem.
This are the steps I followed.
Updated adhoc.csproj to use 4.5.0-rc1. (Basically the same as you referenced above)
Open Visual Studio Enterprise 2017 Preview Version 15.8.0 Preview 6.0
Open Solution
Compile
Set the two breakpoints as indicated in the code
F5 to Run - Hits first breakpoint
F10 - To step through until it hits this line: connection.Open();
Exception thrown.
We can do an interactive session if you would like. Just let me know.
keeratsingh commentedon May 30, 2018
@BrotherOdin Thank you for the confirmation and detailed steps to repro the issue. I see we differ in OS environments, your logs suggest you are using
win81-x64while I am trying to repro the issue inwin10-x64. I will try to setup and repro the issue inwin81-x64environment and get back to you.StevenRasmussen commentedon Jun 1, 2018
I think I'm running into a similar issue... although it's kind of intermittent. Sometimes I'll get the error and sometimes I don't. And it doesn't just happen when a breakpoint is set. I know this doesn't really help with troubleshooting but I wanted to let you know that I'm experiencing it too.
keeratsingh commentedon Jun 1, 2018
@SimplerSoftware Thank you for sharing the information. Could you kindly share your
dotnet --infooutput as well.StevenRasmussen commentedon Jun 1, 2018
@keeratsingh - here you go:
.NET Core SDK (reflecting any global.json): Version: 2.1.300 Commit: adab45bf0c Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.300\ Host (useful for support): Version: 2.1.0 Commit: caa7b7e2ba .NET Core SDKs installed: 1.1.0 [C:\Program Files\dotnet\sdk] 2.0.0 [C:\Program Files\dotnet\sdk] 2.0.2 [C:\Program Files\dotnet\sdk] 2.0.3 [C:\Program Files\dotnet\sdk] 2.1.1-preview-007094 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.4 [C:\Program Files\dotnet\sdk] 2.1.100 [C:\Program Files\dotnet\sdk] 2.1.101 [C:\Program Files\dotnet\sdk] 2.1.103 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.200-preview-007474 [C:\Program Files\dotnet\sdk] 2.1.200-preview-007589 [C:\Program Files\dotnet\sdk] 2.1.200 [C:\Program Files\dotnet\sdk] 2.1.201 [C:\Program Files\dotnet\sdk] 2.1.300-preview1-008174 [C:\Program Files\dotnet\sdk] 2.1.300-rc1-008673 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk] .NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0-preview1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0-preview1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0-rc1-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-preview1-26216-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0-rc1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]Edit: Formatted response by @keeratsingh
keeratsingh commentedon Jun 6, 2018
I have setup a Windows 8.1 environment and was able to repro the issue only once against a local 2017 SQLServer, that too on a clean VM, fortunately I was able to capture the dump and trace with the line numbers to have a better picture of the path. I haven't been able to repro this on Windows 10.
On further investigation while debugging through code I found that
System.Data.SqlClientis indeed calling Transaction.EnlistPromotableSinglePhase before it calls GetTransactionCookie.EnlistPromotableSinglePhasemethod call returnstrue, the exception is not seen.EnlistPromotableSinglePhasewere to returnfalseby calling theEnlistNonNullmethod explicitly againsecond time, theEnlistPromotableSinglePhasemethod call returnsfalse, that is when the GetTransactionCookie method gets called and the expection is seen, which is inline with @jimcarley 's comments above.Now the above is just a theory, so far which I have not been able to confirm if
EnlistNonNullis indeed being called twice, since the issue is not reproable consistently.@BrotherOdin Is the issue reproing consistently for you ? Also, to confirm which version of SQLServer are you seeing this issue with, is it local or remote SQLServer ?
13 remaining items
divega commentedon May 15, 2019
As recently announced in the .NET Blog, focus on new SqlClient features an improvements is moving to the new Microsoft.Data.SqlClient package. For this reason, we are moving this issue to the new repo at https://github.com/dotnet/SqlClient. We will still use https://github.com/dotnet/corefx to track issues on other providers like System.Data.Odbc and System.Data.OleDB, and general ADO.NET and .NET data access issues.
coredevsushant commentedon May 27, 2019
do we have any solution
I am running in same issue
with .net core 2.2
cheenamalhotra commentedon Nov 3, 2020
Hi @BrotherOdin @sushantraje2000 @zhangsquall @Alchemy86 @ciragithub
I tested this issue today with provided repro application and I was able to reproduce issue with EF Core v2.1.0-rc1-final
But I tried again with EF Core v3.1.9 (tested both netcoreapp2.1 and netcoreapp3.1) that references Microsoft.Data.SqlClient now and this issue seems to be resolved.
Could someone verify and confirm so we can close this issue?
Thanks!
cheenamalhotra commentedon Aug 5, 2022
@David-Engel @DavoudEshtehari
I wonder if this can be closed since there is no activity or reports of the same?
JRahnama commentedon Aug 9, 2022
Closing due to inactivity. Feel free to comment if still experiencing the issue.
Address PR review: fix </param>, expand WamBroker tests, README note
Address PR #4336 review feedback (pipeline version computation)