Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » ADO.NET » Downloads
 
Add your own
alternative version

Declarative Transactions using ADO.NET and without Enterprise Services.

, 26 Oct 2001
Sometimes it is nice to prototype up a simple database application. This code may help, by providing the automatic transactional model of COM+ in a non-COM+ environment. This example uses "Interception" to provide automatic transactioning support for non-COM+ classes.
declarativetransactions_src.zip
codeproject_template
TransactionAttribute
bin
Debug
obj
Debug
temp
TempPE
TransactionAttribute.csproj.user
TransactionExample
bin
Debug
obj
Debug
temp
TempPE
TransactionExample.csproj.user
TransactionExample.suo
using System;
using System.Threading;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Messaging;
using System.Data.SqlClient;
using System.Data;

namespace RSI.Transactions
{
	[DbConnection]
	[Transaction(TransactionOption.Required)]
	class TestClass1 : ContextBoundObject
	{
		public				TestClass1() {}

		[AutoComplete]
		public void			TrxRequired() 
		{
			TestClass2 tc2 = new TestClass2();
//			throw new System.Exception("This is an exception");
			tc2.TrxRequired();
			TrxRequired2("ooga");
			tc2.TrxRequired2("booga");
//			ContextUtil.SetComplete();
		}

		[AutoComplete]
		public void			TrxRequired2(string strText) 
		{
		}
	}

	[Transaction(TransactionOption.RequiresNew)]
	[DbConnection]
	class TestClass2 : ContextBoundObject
	{
		public				TestClass2() {}

		[AutoComplete]
		public void			TrxRequired() 
		{
			TrxRequired2("ooga");
		}

		[AutoComplete]
		public void			TrxRequired2(string strText) 
		{
		}
	}

	class Class1
	{
		static void Main(string[] args)
		{
			//
			// TODO: Add code to start application here
			//
			try
			{
				TestClass1 tc1 = new TestClass1();
				tc1.TrxRequired();
			}
			catch(System.Exception exc)
			{
				System.Console.WriteLine(exc.Message);
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sandy Place

Canada Canada
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 27 Oct 2001
Article Copyright 2001 by Sandy Place
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid