Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Performing Transactions in Windows Workflow

A transaction-oriented application is one of the common things that developers are tasked with handling, but that doesn't mean it's easy. Transactions are tricky thanks to tricky rollback conditions that must execute flawlessly. Find out why Windows Workflow can take the pain out of building transactions with a visual roadmap.


advertisement
transaction is a very common operation in our daily lives as well as in the computing world. For example, when you try to deposit a check issued by your boss, the bank first needs to debit the stated amount from your boss's account before the money is credited into your account. If your boss does not have sufficient funds in his account, the money will not be credited into your account. Similarly, after debiting the money from your boss's account, if the bank is not able to credit the money into your account for some reason (perhaps you cancelled the account), the amount will be credited back to your boss's account. As you can see, for this transaction to be successful, these two operations must complete, or else any one of the operations needs to be rolled back (reversed).

In this article, I will show you how transactions are implemented in Windows Workflow. By using the transactions support in Windows Workflow, you can drastically reduce the overhead needed to write custom code to implement transactional behavior.

What You Need
For this article, you need the following components:
—Visual Studio 2005
—Microsoft Pre-Release Software Microsoft .NET Framework 3.0--Release Candidate
—Microsoft Visual Studio 2005 Extensions for Windows Workflow Foundation Release Candidate 5

To implement workflow transactions, you need to install the SqlPersistenceService database as outlined in my previous article, "Execute a Long-Running Workflow Using Persistence in Windows WF."



Author's Note: For the 3.0 release of the .NET Framework, the path to the SQL scripts is: C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN.

Preparing the Database
In this article, I will create a simple application, using Windows Workflow, to show how funds can be transferred from one account to another and how to use transactions to ensure that the transfer is performed correctly.

The first step to creating the application is to create the database to store the bank account information.

In Visual Studio 2005, go to Server Explorer (View | Server Explorer). Right-click on Data Connections and select Create New SQL Server Database… (see Figure 1).


Figure 1. Create a new SQL Server database. This will be used to store the bank account information for the sample application.
 
Figure 2. Give the new database a name. I chose BankDatabase.

In the text box for the Server name enter ".\SQLEXPRESS" (assuming you have SQL Server 2005 Express edition installed locally on your development machine). Name the database BankDatabase (see Figure 2).

The database will now be created and will appear under the Data Connections item in Server Explorer. Now I want to add a new Table to the database. Expand the new database name, right-click on Tables (see Figure 3), and select Add New Table.


Figure 3. Add a new table to a database.
 
Figure 4. Define the fields in the table.

Define the fields for your new table as shown in Figure 4. Click the Save icon and name the table Accounts.

Now that the table is defined, I want to populate it with some data. Right-click on the Accounts table name in Server Explorer and select Show Table Data (see Figure 5).


Figure 5. View the content in the table.
 
Figure 6. Populate the table with two records.

Populate the Accounts table with the data shown in Figure 6. The first column represents two bank customers while the second column is their respective bank balances.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap