|
1 | 1 | ---
|
2 | 2 | title: Distributed transactions across cloud databases (preview)
|
3 | 3 | description: Overview of Elastic Database Transactions with Azure SQL Database and Azure SQL Managed Instance.
|
4 |
| -services: sql-database |
5 | 4 | ms.service: sql-database
|
6 | 5 | ms.subservice: scale-out
|
7 | 6 | ms.custom: sqldbrb=1
|
8 |
| -ms.devlang: |
9 | 7 | ms.topic: conceptual
|
10 | 8 | author: scoriani
|
11 | 9 | ms.author: scoriani
|
@@ -77,7 +75,7 @@ Note that the installer for .NET 4.6.1 may require more temporary storage during
|
77 | 75 |
|
78 | 76 | ### Multi-database applications
|
79 | 77 |
|
80 |
| -The following sample code uses the familiar programming experience with .NET System.Transactions. The TransactionScope class establishes an ambient transaction in .NET. (An “ambient transaction” is one that lives in the current thread.) All connections opened within the TransactionScope participate in the transaction. If different databases participate, the transaction is automatically elevated to a distributed transaction. The outcome of the transaction is controlled by setting the scope to complete to indicate a commit. |
| 78 | +The following sample code uses the familiar programming experience with .NET System.Transactions. The TransactionScope class establishes an ambient transaction in .NET. (An "ambient transaction" is one that lives in the current thread.) All connections opened within the TransactionScope participate in the transaction. If different databases participate, the transaction is automatically elevated to a distributed transaction. The outcome of the transaction is controlled by setting the scope to complete to indicate a commit. |
81 | 79 |
|
82 | 80 | ```csharp
|
83 | 81 | using (var scope = new TransactionScope())
|
@@ -175,51 +173,51 @@ The following sample Transact-SQL code uses [BEGIN DISTRIBUTED TRANSACTION](/sql
|
175 | 173 | Here is an example where transaction is explicitly promoted to distributed transaction with Transact-SQL.
|
176 | 174 |
|
177 | 175 | ```csharp
|
178 |
| - using (TransactionScope s = new TransactionScope()) |
179 |
| - { |
180 |
| - using (SqlConnection conn = new SqlConnection(DB0_ConnectionString) |
181 |
| - { |
182 |
| - conn.Open(); |
183 |
| - |
184 |
| - // Transaction is here promoted to distributed by BEGIN statement |
185 |
| - // |
186 |
| - Helper.ExecuteNonQueryOnOpenConnection(conn, "BEGIN DISTRIBUTED TRAN"); |
187 |
| - // ... |
188 |
| - } |
189 |
| - |
190 |
| - using (SqlConnection conn2 = new SqlConnection(DB1_ConnectionString) |
191 |
| - { |
192 |
| - conn2.Open(); |
193 |
| - // ... |
194 |
| - } |
195 |
| - |
196 |
| - s.Complete(); |
197 |
| - } |
| 176 | + using (TransactionScope s = new TransactionScope()) |
| 177 | + { |
| 178 | + using (SqlConnection conn = new SqlConnection(DB0_ConnectionString) |
| 179 | + { |
| 180 | + conn.Open(); |
| 181 | + |
| 182 | + // Transaction is here promoted to distributed by BEGIN statement |
| 183 | + // |
| 184 | + Helper.ExecuteNonQueryOnOpenConnection(conn, "BEGIN DISTRIBUTED TRAN"); |
| 185 | + // ... |
| 186 | + } |
| 187 | + |
| 188 | + using (SqlConnection conn2 = new SqlConnection(DB1_ConnectionString) |
| 189 | + { |
| 190 | + conn2.Open(); |
| 191 | + // ... |
| 192 | + } |
| 193 | + |
| 194 | + s.Complete(); |
| 195 | + } |
198 | 196 | ```
|
199 | 197 |
|
200 | 198 | Following example shows a transaction that is implicitly promoted to distributed transaction once the second SqlConnecton was started within the TransactionScope.
|
201 | 199 |
|
202 | 200 | ```csharp
|
203 |
| - using (TransactionScope s = new TransactionScope()) |
204 |
| - { |
205 |
| - using (SqlConnection conn = new SqlConnection(DB0_ConnectionString) |
206 |
| - { |
207 |
| - conn.Open(); |
208 |
| - // ... |
209 |
| - } |
210 |
| - |
211 |
| - using (SqlConnection conn = new SqlConnection(DB1_ConnectionString) |
212 |
| - { |
213 |
| - // Because this is second SqlConnection within TransactionScope transaction is here implicitly promoted distributed. |
214 |
| - // |
215 |
| - conn.Open(); |
216 |
| - Helper.ExecuteNonQueryOnOpenConnection(conn, "BEGIN DISTRIBUTED TRAN"); |
217 |
| - Helper.ExecuteNonQueryOnOpenConnection(conn, lsQuery); |
218 |
| - // ... |
219 |
| - } |
220 |
| - |
221 |
| - s.Complete(); |
222 |
| - } |
| 201 | + using (TransactionScope s = new TransactionScope()) |
| 202 | + { |
| 203 | + using (SqlConnection conn = new SqlConnection(DB0_ConnectionString) |
| 204 | + { |
| 205 | + conn.Open(); |
| 206 | + // ... |
| 207 | + } |
| 208 | + |
| 209 | + using (SqlConnection conn = new SqlConnection(DB1_ConnectionString) |
| 210 | + { |
| 211 | + // Because this is second SqlConnection within TransactionScope transaction is here implicitly promoted distributed. |
| 212 | + // |
| 213 | + conn.Open(); |
| 214 | + Helper.ExecuteNonQueryOnOpenConnection(conn, "BEGIN DISTRIBUTED TRAN"); |
| 215 | + Helper.ExecuteNonQueryOnOpenConnection(conn, lsQuery); |
| 216 | + // ... |
| 217 | + } |
| 218 | + |
| 219 | + s.Complete(); |
| 220 | + } |
223 | 221 | ```
|
224 | 222 |
|
225 | 223 | ## Transactions across multiple servers for Azure SQL Database
|
@@ -274,8 +272,7 @@ The following limitations currently apply to distributed transactions in Managed
|
274 | 272 | ![Private endpoint connectivity limitation][4]
|
275 | 273 | ## Next steps
|
276 | 274 |
|
277 |
| -* For questions, reach out to us on the [Microsoft Q&A question page for SQL Database](/answers/topics/azure-sql-database.html). |
278 |
| -* For feature requests, add them to the [SQL Database feedback forum](https://feedback.azure.com/forums/217321-sql-database/) or [Managed Instance forum](https://feedback.azure.com/forums/915676-sql-managed-instance). |
| 275 | +* For questions, reach out to us on the [Microsoft Q&A question page for SQL Database](/answers/topics/azure-sql-database.html).https://feedback.azure.com/d365community/forum/04fe6ee0-3b25-ec11-b6e6-000d3a4f0da0) or [Managed Instance forum](https://feedback.azure.com/forums/915676-sql-managed-instance). |
279 | 276 |
|
280 | 277 |
|
281 | 278 |
|
|
0 commit comments