Skip to content

Commit 485ee00

Browse files
committed
Fixing next steps on elastic-transactions-overview.md
1 parent dd1e80f commit 485ee00

File tree

1 file changed

+111
-118
lines changed

1 file changed

+111
-118
lines changed

articles/azure-sql/database/elastic-transactions-overview.md

Lines changed: 111 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,24 @@ For Azure App Service, upgrades to the guest OS are currently not supported. For
5151
Note that the installer for .NET 4.6.1 may require more temporary storage during the bootstrapping process on Azure cloud services than the installer for .NET 4.6. To ensure a successful installation, you need to increase temporary storage for your Azure cloud service in your ServiceDefinition.csdef file in the LocalResources section and the environment settings of your startup task, as shown in the following sample:
5252

5353
```xml
54-
<LocalResources>
54+
<LocalResources>
55+
...
56+
<LocalStorage name="TEMP" sizeInMB="5000" cleanOnRoleRecycle="false" />
57+
<LocalStorage name="TMP" sizeInMB="5000" cleanOnRoleRecycle="false" />
58+
</LocalResources>
59+
<Startup>
60+
<Task commandLine="install.cmd" executionContext="elevated" taskType="simple">
61+
<Environment>
5562
...
56-
<LocalStorage name="TEMP" sizeInMB="5000" cleanOnRoleRecycle="false" />
57-
<LocalStorage name="TMP" sizeInMB="5000" cleanOnRoleRecycle="false" />
58-
</LocalResources>
59-
<Startup>
60-
<Task commandLine="install.cmd" executionContext="elevated" taskType="simple">
61-
<Environment>
62-
...
63-
<Variable name="TEMP">
64-
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='TEMP']/@path" />
65-
</Variable>
66-
<Variable name="TMP">
67-
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='TMP']/@path" />
68-
</Variable>
69-
</Environment>
70-
</Task>
71-
</Startup>
63+
<Variable name="TEMP">
64+
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='TEMP']/@path" />
65+
</Variable>
66+
<Variable name="TMP">
67+
<RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='TMP']/@path" />
68+
</Variable>
69+
</Environment>
70+
</Task>
71+
</Startup>
7272
```
7373

7474
## .NET development experience
@@ -78,26 +78,24 @@ Note that the installer for .NET 4.6.1 may require more temporary storage during
7878
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.
7979

8080
```csharp
81-
using (var scope = new TransactionScope())
81+
using (var scope = new TransactionScope())
82+
{
83+
using (var conn1 = new SqlConnection(connStrDb1))
8284
{
83-
using (var conn1 = new SqlConnection(connStrDb1))
84-
{
85-
conn1.Open();
86-
SqlCommand cmd1 = conn1.CreateCommand();
87-
cmd1.CommandText = string.Format("insert into T1 values(1)");
88-
cmd1.ExecuteNonQuery();
89-
}
90-
91-
using (var conn2 = new SqlConnection(connStrDb2))
92-
{
93-
conn2.Open();
94-
var cmd2 = conn2.CreateCommand();
95-
cmd2.CommandText = string.Format("insert into T2 values(2)");
96-
cmd2.ExecuteNonQuery();
97-
}
98-
99-
scope.Complete();
85+
conn1.Open();
86+
SqlCommand cmd1 = conn1.CreateCommand();
87+
cmd1.CommandText = string.Format("insert into T1 values(1)");
88+
cmd1.ExecuteNonQuery();
10089
}
90+
using (var conn2 = new SqlConnection(connStrDb2))
91+
{
92+
conn2.Open();
93+
var cmd2 = conn2.CreateCommand();
94+
cmd2.CommandText = string.Format("insert into T2 values(2)");
95+
cmd2.ExecuteNonQuery();
96+
}
97+
scope.Complete();
98+
}
10199
```
102100

103101
### Sharded database applications
@@ -106,24 +104,22 @@ Elastic database transactions for SQL Database and Managed Instance also support
106104
The following code sample illustrates this approach. It assumes that a variable called shardmap is used to represent a shard map from the elastic database client library:
107105

108106
```csharp
109-
using (var scope = new TransactionScope())
107+
using (var scope = new TransactionScope())
108+
{
109+
using (var conn1 = shardmap.OpenConnectionForKey(tenantId1, credentialsStr))
110110
{
111-
using (var conn1 = shardmap.OpenConnectionForKey(tenantId1, credentialsStr))
112-
{
113-
SqlCommand cmd1 = conn1.CreateCommand();
114-
cmd1.CommandText = string.Format("insert into T1 values(1)");
115-
cmd1.ExecuteNonQuery();
116-
}
117-
118-
using (var conn2 = shardmap.OpenConnectionForKey(tenantId2, credentialsStr))
119-
{
120-
var cmd2 = conn2.CreateCommand();
121-
cmd2.CommandText = string.Format("insert into T1 values(2)");
122-
cmd2.ExecuteNonQuery();
123-
}
124-
125-
scope.Complete();
111+
SqlCommand cmd1 = conn1.CreateCommand();
112+
cmd1.CommandText = string.Format("insert into T1 values(1)");
113+
cmd1.ExecuteNonQuery();
126114
}
115+
using (var conn2 = shardmap.OpenConnectionForKey(tenantId2, credentialsStr))
116+
{
117+
var cmd2 = conn2.CreateCommand();
118+
cmd2.CommandText = string.Format("insert into T1 values(2)");
119+
cmd2.ExecuteNonQuery();
120+
}
121+
scope.Complete();
122+
}
127123
```
128124

129125
## Transact-SQL development experience
@@ -133,35 +129,32 @@ A server-side distributed transactions using Transact-SQL are available only for
133129
The following sample Transact-SQL code uses [BEGIN DISTRIBUTED TRANSACTION](/sql/t-sql/language-elements/begin-distributed-transaction-transact-sql) to start distributed transaction.
134130

135131
```Transact-SQL
136-
137-
-- Configure the Linked Server
138-
-- Add one Azure SQL Managed Instance as Linked Server
139-
EXEC sp_addlinkedserver
140-
@server='RemoteServer', -- Linked server name
141-
@srvproduct='',
142-
@provider='sqlncli', -- SQL Server Native Client
143-
@datasrc='managed-instance-server.46e7afd5bc81.database.windows.net' -- Managed Instance endpoint
144-
145-
-- Add credentials and options to this Linked Server
146-
EXEC sp_addlinkedsrvlogin
147-
@rmtsrvname = 'RemoteServer', -- Linked server name
148-
@useself = 'false',
149-
@rmtuser = '<login_name>', -- login
150-
@rmtpassword = '<secure_password>' -- password
151-
152-
USE AdventureWorks2012;
153-
GO
154-
SET XACT_ABORT ON;
155-
GO
156-
BEGIN DISTRIBUTED TRANSACTION;
157-
-- Delete candidate from local instance.
158-
DELETE AdventureWorks2012.HumanResources.JobCandidate
159-
WHERE JobCandidateID = 13;
160-
-- Delete candidate from remote instance.
161-
DELETE RemoteServer.AdventureWorks2012.HumanResources.JobCandidate
162-
WHERE JobCandidateID = 13;
163-
COMMIT TRANSACTION;
164-
GO
132+
-- Configure the Linked Server
133+
-- Add one Azure SQL Managed Instance as Linked Server
134+
EXEC sp_addlinkedserver
135+
@server='RemoteServer', -- Linked server name
136+
@srvproduct='',
137+
@provider='sqlncli', -- SQL Server Native Client
138+
@datasrc='managed-instance-server.46e7afd5bc81.database.windows.net' -- Managed Instance endpoint
139+
-- Add credentials and options to this Linked Server
140+
EXEC sp_addlinkedsrvlogin
141+
@rmtsrvname = 'RemoteServer', -- Linked server name
142+
@useself = 'false',
143+
@rmtuser = '<login_name>', -- login
144+
@rmtpassword = '<secure_password>' -- password
145+
USE AdventureWorks2012;
146+
GO
147+
SET XACT_ABORT ON;
148+
GO
149+
BEGIN DISTRIBUTED TRANSACTION;
150+
-- Delete candidate from local instance.
151+
DELETE AdventureWorks2012.HumanResources.JobCandidate
152+
WHERE JobCandidateID = 13;
153+
-- Delete candidate from remote instance.
154+
DELETE RemoteServer.AdventureWorks2012.HumanResources.JobCandidate
155+
WHERE JobCandidateID = 13;
156+
COMMIT TRANSACTION;
157+
GO
165158
```
166159

167160
## Combining .NET and Transact-SQL development experience
@@ -173,51 +166,51 @@ The following sample Transact-SQL code uses [BEGIN DISTRIBUTED TRANSACTION](/sql
173166
Here is an example where transaction is explicitly promoted to distributed transaction with Transact-SQL.
174167

175168
```csharp
176-
using (TransactionScope s = new TransactionScope())
169+
using (TransactionScope s = new TransactionScope())
170+
{
171+
using (SqlConnection conn = new SqlConnection(DB0_ConnectionString)
177172
{
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();
173+
conn.Open();
174+
175+
// Transaction is here promoted to distributed by BEGIN statement
176+
//
177+
Helper.ExecuteNonQueryOnOpenConnection(conn, "BEGIN DISTRIBUTED TRAN");
178+
// ...
195179
}
180+
 
181+
using (SqlConnection conn2 = new SqlConnection(DB1_ConnectionString)
182+
{
183+
conn2.Open();
184+
// ...
185+
}
186+
187+
s.Complete();
188+
}
196189
```
197190

198191
Following example shows a transaction that is implicitly promoted to distributed transaction once the second SqlConnecton was started within the TransactionScope.
199192

200193
```csharp
201-
using (TransactionScope s = new TransactionScope())
194+
using (TransactionScope s = new TransactionScope())
195+
{
196+
using (SqlConnection conn = new SqlConnection(DB0_ConnectionString)
202197
{
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();
198+
conn.Open();
199+
// ...
220200
}
201+
202+
using (SqlConnection conn = new SqlConnection(DB1_ConnectionString)
203+
{
204+
// Because this is second SqlConnection within TransactionScope transaction is here implicitly promoted distributed.
205+
//
206+
conn.Open();
207+
Helper.ExecuteNonQueryOnOpenConnection(conn, "BEGIN DISTRIBUTED TRAN");
208+
Helper.ExecuteNonQueryOnOpenConnection(conn, lsQuery);
209+
// ...
210+
}
211+
212+
s.Complete();
213+
}
221214
```
222215

223216
## Transactions across multiple servers for Azure SQL Database
@@ -272,9 +265,9 @@ The following limitations currently apply to distributed transactions in Managed
272265
![Private endpoint connectivity limitation][4]
273266
## Next steps
274267

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).
276-
268+
* For questions, reach out to us on the [Microsoft Q&A question page for SQL Database](/answers/topics/azure-sql-database.html).
277269

270+
* For feature requests, add them to the [SQL Database feedback forum](https://feedback.azure.com/d365community/forum/04fe6ee0-3b25-ec11-b6e6-000d3a4f0da0) or [Managed Instance forum](https://feedback.azure.com/d365community/forum/a99f7006-3425-ec11-b6e6-000d3a4f0f84).
278271
279272
<!--Image references-->
280273
[1]: ./media/elastic-transactions-overview/distributed-transactions.png

0 commit comments

Comments
 (0)