This step-by-step article demonstrates how to create a serviced .NET component that uses transactions. This article also demonstrates how to create a client that tests your serviced component. Microsoft Enterprise Services provides Microsoft COM+ services to .NET components.
Serviced components require strong names.
Serviced components should be registered in the Global Assembly Cache (GAC) because they are system-level resources. Server applications require installation in the GAC, but library applications do not (although it is recommended).
You can register serviced components with COM+ either automatically through lazy registration or manually through the Regsvcs.exe utility. Regsvcs.exe is located in the following folder:
For more information about Regsvcs.exe, refer to the Microsoft .NET Framework Software Development Kit (SDK) documentation.
This sample assumes that Microsoft SQL Server has been installed on the local computer.
This sample is intended only for illustration purposes. Strictly speaking, this sample's select query is a good candidate to run outside of a COM+ transaction because COM+ uses the highest isolation level for the transaction. To improve database throughput, it is good programming practice to consider read queries for lower transaction levels.
Create the Serviced .NET Component
Create a new Visual C# Class Library project named ServicedCOM.
Rename your default class and the filename from Class1.cs to SimpleTrans.cs. to do this, follow these steps:
In the Class View window, right-click Class1, and then click Properties.
In Properties, change the Name property to SimpleTrans.
Add a reference to the System.EnterpriseServices namespace.
Add the following statement, as the top line, to both SimpleTrans.cs and AssemblyInfo.cs:
At the top of SimpleTrans.cs add the following statement:
Inherit your class from ServicedComponent (fully qualified name: System.EnterpriseServices.ServicedComponent).
Add the following code just before the *public class* declaration:
Add the following recommended attributes to AssemblyInfo.cs: