File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/MySqlConnector/MySql.Data.MySqlClient Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,8 @@ public override void EnlistTransaction(System.Transactions.Transaction transacti
108
108
ImplicitTransactionBase implicitTransaction ;
109
109
if ( m_connectionSettings . UseXaTransactions )
110
110
{
111
+ if ( ! ( existingConnection ? . m_connectionSettings . UseXaTransactions ?? true ) )
112
+ throw new NotSupportedException ( "Cannot start an XA transaction when there is an existing non-XA transaction." ) ;
111
113
implicitTransaction = new XaImplicitTransaction ( this ) ;
112
114
}
113
115
else
Original file line number Diff line number Diff line change @@ -555,6 +555,42 @@ public void TwoDifferentConnectionStringsThrowsWithNonXaTransactions()
555
555
}
556
556
}
557
557
558
+ #if ! BASELINE
559
+ [ Fact ]
560
+ public void CannotMixXaAndNonXaTransactions ( )
561
+ {
562
+ using ( new TransactionScope ( ) )
563
+ {
564
+ using ( var conn1 = new MySqlConnection ( AppConfig . ConnectionString ) )
565
+ {
566
+ conn1 . Open ( ) ;
567
+
568
+ using ( var conn2 = new MySqlConnection ( AppConfig . ConnectionString + ";UseXaTransactions=False" ) )
569
+ {
570
+ Assert . Throws < NotSupportedException > ( ( ) => conn2 . Open ( ) ) ;
571
+ }
572
+ }
573
+ }
574
+ }
575
+
576
+ [ Fact ]
577
+ public void CannotMixNonXaAndXaTransactions ( )
578
+ {
579
+ using ( new TransactionScope ( ) )
580
+ {
581
+ using ( var conn1 = new MySqlConnection ( AppConfig . ConnectionString + ";UseXaTransactions=False" ) )
582
+ {
583
+ conn1 . Open ( ) ;
584
+
585
+ using ( var conn2 = new MySqlConnection ( AppConfig . ConnectionString ) )
586
+ {
587
+ Assert . Throws < NotSupportedException > ( ( ) => conn2 . Open ( ) ) ;
588
+ }
589
+ }
590
+ }
591
+ }
592
+ #endif
593
+
558
594
DatabaseFixture m_database ;
559
595
}
560
596
}
You can’t perform that action at this time.
0 commit comments