-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distributed Transaction error/issue with .NET 7 #80777
Comments
Tagging subscribers to this area: @roji Issue DetailsThis issue has been moved from a ticket on Developer Community. [severity:It's more difficult to complete my work] [regression] [worked-in:worked in .Net Framework] I have tested it with both the System.Data.SqlClient and Microsoft.Data.SqlClient drivers and get the same error. The only thing coming back in the error message is "Distributed". It seems to have cut off the rest of the error message so I can't tell exactly what it is saying, just that it is related to distributed transaction almost certainly. I managed to get a screen shot which does show the error message though. Our network team has confirmed there are no firewalls blocking access and MSDTC seems to be set correctly on both machines. The current configuration works for distributed transactions in the .Net Framework. Also, if I remove the TransactionScope transaction from my test code, the connections work fine - so I know I can reach the databases. This from a Windows 10 machine. MSDTS has been opened to allow connections. TransactionManager.ImplicitDistributedTransactions has been set to True. Original CommentsFeedback Bot on 12/29/2022, 03:13 AM:(private comment, text removed) Feedback Bot on 1/4/2023, 03:01 AM:(private comment, text removed) Feedback Bot on 1/10/2023, 07:53 AM:(private comment, text removed) Original Solutions(no solutions)
|
This sounds like it could be dotnet/SqlClient#1800, although IIRC the bug is only in Microsoft.Data.SqlClient and System.Data.SqlClient should work fine. I suggested waiting for Microsoft.Data.SqlClient 5.1.0 (should be very soon) and then trying with that. Other than that, I'm going to need a minimal, runnable code sample which produces the problem in order to investigate. |
I have never been able to get distributed transactions to work in .NET 6 or 7 either, even though the same code works fine in .NET Framework 4.8.1. I really would like explicit distributed transactions using CommittableTransaction and DependentTransaction to work, but I've also tried implicit distributed transactions using TransactionScope. I'm using VB.NET in Visual Studio 2022 ver 17.5.2 targeting .NET 7 and SQL Server 2022. I'm using Microsoft.Data.SqlClient 5.1.0, and I also have the latest OLE and ODBC drivers installed on Windows 11 Enterprise 64bit 22H2 build 22621.1413. Here is simple console app code for an explicit distributed transaction (with the strSqlCon declaration omitted). An exception occurs every time a second sql connection enlists.
The same thing happens with an implicit distributed transaction, as soon as the second sql connection is opened.
I can see the transaction being aborted in Component Services under DTC statistics in .NET 7, but it will be committed in .NET Framework 4.8.1. |
The exception I get with explicit transactions after the second enlist in .NET 7 is this: Exception thrown: 'System.NotSupportedException' in System.Transactions.Local.dll The exception I get after the second sql connection opens with implicit transactions in .NET 7 is this: Exception thrown: 'System.NotSupportedException' in Microsoft.Data.SqlClient.dll Note I've tried every combination of "Enlist=[true|false];" and "Transaction Binding=[Implicit|Explicit] Unbind;" in the sql connection string. I've tried setting implicit transactions on in the SQL Server connection options. DTC is configured and firewall exceptions are in place. The exact same code works fine with .NET Framework 4.8.1. |
The .NET 7 distributed transaction support requires that you explicitly opt into it; this is different from .NET Framework, where it was always available. To opt into distributed transactions, add the following at the very start of your program, before starting any transactions: TransactionManager.ImplicitDistributedTransactions = true; This is indeed something we need to document better. Some further responses to your comments:
DIstributed transactions weren't supported in .NET 6.0. Windows-only support was introduced in .NET 7.0 only (#715).
You should be able to use both explicit and implicit distributed transactions. There's no difference between them in terms of support, they're just different API styles.
FWIW neither OleDB nor ODBC are used when using SqlClient, so these shouldn't be necessary. |
I'm going to go ahead and close this issue as the original poster didn't provide a repro, and the 2nd question was answered. However, feel free to continue posting questions here, I'll be happy to answer. |
TransactionManager.ImplicitDistributedTransactions = true That was the missing line. Thanks! I would have never figured that out from any of the online documentation, especially since I am trying to use explicit distributed transactions. |
This issue has been moved from a ticket on Developer Community.
[severity:It's more difficult to complete my work] [regression] [worked-in:worked in .Net Framework]
When we moved from framework to .NET (previously .NET core), we lost the distributed transaction capability. NET 7 was supposed to address this issue for Window platforms, but we are not able to get it to work. I did a simple test with just two queries to two different SQL databases. Once the Open command is issued on the second database, it will not establish a connection and eventually times out.
I have tested it with both the System.Data.SqlClient and Microsoft.Data.SqlClient drivers and get the same error. The only thing coming back in the error message is "Distributed". It seems to have cut off the rest of the error message so I can't tell exactly what it is saying, just that it is related to distributed transaction almost certainly. I managed to get a screen shot which does show the error message though.
Our network team has confirmed there are no firewalls blocking access and MSDTC seems to be set correctly on both machines. The current configuration works for distributed transactions in the .Net Framework. Also, if I remove the TransactionScope transaction from my test code, the connections work fine - so I know I can reach the databases.
This from a Windows 10 machine. MSDTS has been opened to allow connections. TransactionManager.ImplicitDistributedTransactions has been set to True.
Original Comments
Feedback Bot on 12/29/2022, 03:13 AM:
(private comment, text removed)
Feedback Bot on 1/4/2023, 03:01 AM:
(private comment, text removed)
Feedback Bot on 1/10/2023, 07:53 AM:
(private comment, text removed)
Original Solutions
(no solutions)
The text was updated successfully, but these errors were encountered: