DEV 305 Introducing System.Transactions

Slides:



Advertisements
Similar presentations
Notes: Update as of 1/13/2010. Vulnerabilities are included for SQL Server 2000, SQL Server 2005, SQL Server Oracle (8i, 9i, 9iR2, 10g, 10gR2,11g),
Advertisements

 Josh Honeyman Sr. Development Lead Microsoft Corporation BB57.
Introducing System.Transactions Nigel Watson Architect Advisor Developer Platform Strategy Group Microsoft DAT214.
Ravi Sankar Technology Evangelist | Microsoft Corporation
Conditions and Terms of Use
Distributed Transaction & Long-running transactions Rossen Zhivkov Freelance SharePoint Consultant January 19 th, 2008 Sofia, Bulgaria Krasimir Parushev.
DEV384 COM+ Lives : New Features in Enterprise Services Included in Windows Server 2003 Catherine Heller Senior Consultant Microsoft Spain.
Tips and Tricks for Managing and Administering your Enterprise Project Management Server Solution Mike Joe / Karthik Chermakani Software Test Engineer.
DEV333 Instrumenting Applications for Manageability with the Enterprise Instrumentation Framework David Keogh Program Manager Visual Studio Enterprise.
DAT325 SQL Server 2005 (Codenamed “Yukon”): Using the Service Broker To Build Asynchronous, Queued Database Applications Roger Wolter Program Manager.
DEV395 No Touch Deployment for Windows Forms Jamie Cool Program Manager.NET Client Microsoft Corporation.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 Transations.
JPA Transactions
DISTRIBUTED TRANSACTIONS IN.NET Presented By Divya Josyala.
EBZ306 Advanced Business Process Automation Using BizTalk Server 2004 David Fong Program Manager.
Honor that Transaction How to Design and Code Your Transactions Vineet Gupta Evangelist – Database and Integration Microsoft Corp.
Sage Franch | Technical Evangelist Susan Ibach | Technical Evangelist.
Integrating with Dynamics 365
What’s new in Entity Framework Core 2.0
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Web Technologies IT230 Dr Mohamed Habib.
Integrating with Dynamics 365
Transactions in Entity Framework
Transaction Management and Concurrency Control
Business Connectivity Services in SharePoint 2010 and Office 2010
Let Me Finish... Isolating Write Operations
Managing the Solution Lifecycle for xRM Applications
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Isolation Levels Understanding Transaction Temper Tantrums
Microsoft Build /20/2018 5:17 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Let Me Finish... Isolating Write Operations
9/20/2018 2:30 PM BRK2279 Everything you need to know about the new Windows Server release cadence Chris Van Wesep, Director Product Marketing Jeff Woolsey,
Let Me Finish... Isolating Write Operations
Overview of Social Computing in Microsoft SharePoint 2010
Transforming SharePoint Farm Solutions to the Add-in Model
Microsoft Ignite NZ October 2016 SKYCITY, Auckland.
"Oslo”: Customizing and Extending the Visual Design Experience
Tech·Ed North America /21/2018 6:42 PM
SharePoint hosting 101 Where do I host my apps?
On transactions, and Atomic Operations
TechEd /24/2018 8:21 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Branching and Merging Practices
Turbo-Charged Transaction Logs
High Availability: A Contrarian View
Building event-driven, long-running apps with Windows workflow
Microsoft Virtual Academy
TechEd /9/2018 4:17 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
12/9/2018 Desktop Virtualization Corey Hynes Kyle Rosenthal President Technical Lead HynesITe Inc Spider Consulting @windowspcguy.
On transactions, and Atomic Operations
TechEd /11/ :54 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
TechEd /15/2019 8:08 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
DAT381 Team Development with SQL Server 2005
Let Me Finish... Isolating Write Operations
Let Me Finish... Isolating Write Operations
Introduction to VSTS Database Professional
Pushing Data to and from the Cloud with SQL Azure Data Sync
Feature: Document Attachment - Flow from Master Records
TechEd /3/ :48 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
TechEd /7/2019 1:14 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Sioux Falls, SD | Hosted by (605) SQL
Andrew Fryer Microsoft UK
TechEd /23/2019 9:23 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Code First Development in Microsoft ADO.NET Entity Framework 4.1
Objectives In this lesson, you will learn about:
Server-Side Programming
Global Distribution.
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2018
Office 365 Development July 2014.
Microsoft Virtual Academy
Jamie Cool Program Manager Microsoft
Presentation transcript:

DEV 305 Introducing System.Transactions Sarvashrestha Paliwal Tarun Anand ISV Technical Evangelist Microsoft Most Valuable Professional

Session Overview Transactions in .NET 1.1 Introducing new features in .NET 2.0 Understand the role of the Lightweight Transaction Manager (LTM) Transaction Manager Promotion Transactions Objects TransactionScope Transaction Flow Developing a Resource Manager

Why System.Transactions Transaction programming models in .NET 1.1 Explicit transaction management Declarative transaction management Both models have disadvantages Neither superior to the other in every respect .NET 2.0 unifies benefits of both models Minimizing overhead Minimizing hand crafted code Separate from hosting environment and instance management

Transactions in .NET 1.1

Transactions in .NET 1.1 Pros Cons Transaction Client Obj DB Straightforward Cons Most-suitable for a single object interacting with a single database Transaction Client Obj DB

Transactions in .NET 1.1 Gets even more complex with multiple objects and multiple resources Transaction Client Obj Obj Obj DB DB DB

Transactions in .NET 1.1 Relatively clean code but … Must derive from ServicedComponent Must be in strong named assembly Must register in COM+ Very different from single DB scenario

Transactions in .NET 1.1 What happens if the DB update fails? The hashtable value is lost!

.NET 2.0 Transaction One uniform programming model Will use local transaction when Transaction inside a single app domain Transaction involves at most a single durable RM Uses only intra-app domain calls

.NET 2.0 Transaction Will use distributed transaction when Remote calls Multiple durable resources Uses the old DTC with minor changes

Transaction Manager Promotion Every System.Transactions transaction starts as local transaction Single object interacts with single durable resource Only requires local transaction Yields best throughput and performance Transaction promoted when Transaction flows to another object in another app domain Enlisting another durable RM

Transactions Objects Transaction represents transaction for all transaction managers Disposable Transaction used to abort [Serializable] public class Transaction : IDisposable,ISerializable { public void Rollback(); //Abort the transaction public void Dispose(); //Other members }

Transactions Objects Additional functionality of Transaction Enlist RM Set isolation level Obtain transaction information Clone transaction Completion event

Transactions Objects CommittableTransaction used to commit transaction Additional functionality Asynchronous commit [Serializable] public sealed class CommittableTransaction : Transaction,IAsyncResult { public void Commit(); //Other members }

Declarative Model in .NET 2.0 Requires ES out of the box ADO.NET is aware of System.Transactions ES code is same as in .NET 1.1 Existing components benefit automatically Maintains productivity advantages Eliminating performance penalty using System.EnterpriseServices; [Transaction] //Uses System.Transactions, gets promotion public class MyComponent : ServicedComponent { [AutoComplete] public void MyMethod() {...} }

Explicit Model in .NET 2.0 Via TransactionScope public class TransactionScope : IDisposable { public void Complete(); public void Dispose(); public TransactionScope(); public TransactionScope(Transaction transactionToUse); public TransactionScope(TransactionScopeOption scopeOption); public TransactionScope(TransactionScopeOption scopeOption, TransactionOptions transactionOptions); TimeSpan scopeTimeout); //Additional constructors }

TransactionScope Provides ambient transaction to code section Creates transaction Sets Transaction.Current Disposable object Transaction ends once disposed Requires committable transaction

TransactionScope Complete() sets consistency bit to true Scope maintains consistency bit Defaults to false Transaction aborts if consistency bit is false Complete() sets consistency bit to true Transaction will try to commit No way to set back to false using(TransactionScope scope = new TransactionScope()) { /* Perform transactional work here */ //No errors - commit transaction scope.Complete(); }

Ambient Transaction

TransactionScope Can only call Complete() once InvalidOperationException After Complete() is called, cannot access Transaction.Current Can access again after Dispose()

TransactionScope Dispose() restores original ambient If code takes long time to complete: May be indicative of transactional deadlock Default timeout is 60 seconds Transaction will abort automatically If Dispose() never called: Transaction aborts once timeout is expired

TransactionScope Dispose() throws TransactionAbortedException if fails to commit Can alert user or log error Usually better to let exception propagate up No need to abort in catch block

Transaction Flow Management Scopes can nest directly //Direct scope nesting using(TransactionScope scope1 = new TransactionScope()) { using(TransactionScope scope2 = new TransactionScope()) /* Perform transactional work here, vote on scope2 */ scope2.Complete(); } scope1.Complete();

Transaction Flow Management Scopes can nest indirectly //Indirect scope nesting. void RootMethod() { using(TransactionScope scope = new TransactionScope()) SomeMethod(); scope.Complete(); } void SomeMethod()

Transaction Flow Management Top-most scope is called root scope TransactionScope has constructors that accept TransactionScopeOption public enum TransactionScopeOption { Required, RequiresNew, Suppress } TransactionScope scope; scope = new TransactionScope(TransactionScopeOption.Required); using(scope) {…}

Transaction Flow Management Default is TransactionScopeOption.Required TransactionScopeOption controls transaction flow into nested scope Decided at construction time

Transaction Flow Management Flow decided based on ambient transaction and TransactionScopeOption TransactionScopeOption Ambient Transaction The scope will take part in Required No New Transaction (will be the root) Requires New Suppress No Transaction Yes

Transaction Flow

Transaction Flow Management Transaction A No Ambient Transaction Code block {Required} 1 {Required} 2 {Suppress} 4 Transaction B {RequiresNew} 3

Developing a Resource Manager In the future, MS will provide transaction aware versions of System.Collections, System.IO, etc. Other managed data providers (not just SqlClient) But, .NET 2.0 provides facilities for implementing a custom RM Implement IEnlistmentNotification for auto enlistment, rollback and commit behavior

Developing a Resource Manager Distributed Tx Coordinator (DTC) Lightweight Transaction Manager (LTM) Etc. Transaction Manager SQL Server 2005 Oracle MSMQ Transacted Hashtable Resource Manager Application

Developing Resource Manager

Summary Huge Transactions improvements in .NET 2.0 Simple programming model Start fast with the LTM; stays in the LTM if volatile RM Automatically promotes transaction when needed Support for building custom RMs Use more transactions in your applications! Transactions are not just for databases anymore

Your Feedback is Important! Please Fill Out a Survey for This Session on CommNet

© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.