@@ -97,6 +97,74 @@ public override void BeginTransaction(IsolationLevel isolationLevel)
97
97
activeTransaction = underlyingConnection . BeginTransaction ( isolationLevel ) ;
98
98
}
99
99
100
+ /// <inheritdoc/>
101
+ public override void Commit ( )
102
+ {
103
+ EnsureIsNotDisposed ( ) ;
104
+ EnsureTransactionIsActive ( ) ;
105
+
106
+ try {
107
+ if ( ! IsTransactionZombied ( ) ) {
108
+ ActiveTransaction . Commit ( ) ;
109
+ }
110
+ }
111
+ finally {
112
+ ActiveTransaction . Dispose ( ) ;
113
+ ClearActiveTransaction ( ) ;
114
+ }
115
+ }
116
+
117
+ /// <inheritdoc/>
118
+ public override async Task CommitAsync ( CancellationToken token = default )
119
+ {
120
+ EnsureIsNotDisposed ( ) ;
121
+ EnsureTransactionIsActive ( ) ;
122
+
123
+ try {
124
+ if ( ! IsTransactionZombied ( ) ) {
125
+ await ActiveTransaction . CommitAsync ( token ) . ConfigureAwait ( false ) ;
126
+ }
127
+ }
128
+ finally {
129
+ await ActiveTransaction . DisposeAsync ( ) . ConfigureAwait ( false ) ;
130
+ ClearActiveTransaction ( ) ;
131
+ }
132
+ }
133
+
134
+ /// <inheritdoc/>
135
+ public override void Rollback ( )
136
+ {
137
+ EnsureIsNotDisposed ( ) ;
138
+ EnsureTransactionIsActive ( ) ;
139
+
140
+ try {
141
+ if ( ! IsTransactionZombied ( ) ) {
142
+ ActiveTransaction . Rollback ( ) ;
143
+ }
144
+ }
145
+ finally {
146
+ ActiveTransaction . Dispose ( ) ;
147
+ ClearActiveTransaction ( ) ;
148
+ }
149
+ }
150
+
151
+ /// <inheritdoc/>
152
+ public override async Task RollbackAsync ( CancellationToken token = default )
153
+ {
154
+ EnsureIsNotDisposed ( ) ;
155
+ EnsureTransactionIsActive ( ) ;
156
+
157
+ try {
158
+ if ( ! IsTransactionZombied ( ) ) {
159
+ await ActiveTransaction . RollbackAsync ( token ) . ConfigureAwait ( false ) ;
160
+ }
161
+ }
162
+ finally {
163
+ await ActiveTransaction . DisposeAsync ( ) . ConfigureAwait ( false ) ;
164
+ ClearActiveTransaction ( ) ;
165
+ }
166
+ }
167
+
100
168
/// <inheritdoc/>
101
169
public override void MakeSavepoint ( string name )
102
170
{
@@ -200,6 +268,11 @@ private async Task OpenWithCheckAsync(string checkQueryString, CancellationToken
200
268
}
201
269
}
202
270
271
+ private bool IsTransactionZombied ( )
272
+ {
273
+ return ActiveTransaction != null && ActiveTransaction . Connection == null ;
274
+ }
275
+
203
276
// Constructors
204
277
205
278
public Connection ( SqlDriver driver , bool checkConnection )
0 commit comments