System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q306296
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 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.
The ActivationOption attribute indicates whether the component will be activated within the caller's process. You can set Activation.Option to Library or to Server.
The ApplicationName attribute is the name that appears for the COM+ application in the COM+ Catalog and the Component Services Administration console.
Add the following optional attribute to SimpleTrans.cs, just after the using statements:
[assembly: Description("Simple Transactional application to show Enterprise Services")]
This attribute provides a description for the COM+ application in the COM+ Catalog and Component Services Administration console.
Click Start, point to Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.
At the command prompt, type sn.exe -k ServicedCOM.snk to give your assembly a strong name.
For information about signing assemblies with strong names, refer to the .NET Framework Software Development Kit (SDK) documentation.
Copy ServicedCOM.snk to the project folder.
In AssemblyInfo.cs, replace the AssemblykeyFile code with the following code:
You can allow the component to register dynamically when the first instance is created, or you can manually register the component with Regsvcs.exe. To use Regsvcs.exe, follow these steps:
Click Start, point to Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.
At the command prompt, type regsvcs servicedcom.dll. This creates a COM+ library application with the same name as your class name. Ignore the warning message.