Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
SQL Server

Implementing ESC (Enterprise Services Components) in .net 2.0 (First Part)

Author: Zunnair

In this article I will explain the way in which we can create the Enterprise Services Components. Enterprise Services Components are very useful in professional applications.

This application offers a simple system for maintaining a database of suppliers and products. It provides functions for adding updating, retrieving and deleting suppliers and products. All database access is simulated.

  • Invokes COM+ Services for implementing transactions, just-in-time activation, object pooling and object construction.
  • Uses Dynamic Registration to add Enterprise Components to the COM+ Catalog.

There are two classes, Supplier and Product, that form the basis for the components in this application.

Source code is given with that article. So for proper understanding Follow the instructions below.

1-Create a Supplier class from add new Components.


Imports System.Data.SqlClient

Imports System.EnterpriseServices


These attributes set the component up for its interaction with COM+. Transaction(TransactionOption.Required)This component requires a Transaction.


JustInTimeActivation(True)COM+ will activate and deactivate the object as needed, conserving resources when the object is not actively in use.

ObjectPooling(Enabled:=True, MinPoolSize:=2, MaxPoolSize:=10) The component uses Object Pooling, which lets you create a pool of objects that won't be destroyed when they're released. Object pooling increases performance for objects that are expensive to create. This component will hold at least 2 objects and a maximum of 10 in its pool at any given time. ConstructionEnabledAttribute(Default:="Server=localhost;


 DataBase=Northwind;Integrated Security=SSPI" The component's Object Construction string. See the Construct method below for more.


<Transaction(TransactionOption.Required), _

JustInTimeActivation(True), _

ObjectPooling(Enabled:=True, MinPoolSize:=2, MaxPoolSize:=10), ConstructionEnabledAttribute(Default:="Server=localhost;DataBase=Northwind;Integrated Security=SSPI")> _


2-Default constructor. Set the default connection string. If we're using the component in COM+, this value will get overriden later in the Construct method.


Public Sub New()


        m_strConnectionString = SQL_CONNECTION_STRING

        DoTracing("Supplier instantiated at " & DateTime.Now.ToLongTimeString)

    End Sub


3-Construct method applies only when the component is part of a

COM+ application. This method gets called right after the constructor. The constructString parameter contains the class's default property, which was set above in the ConstructionEnabledAttribute. The default string appears in the COM+ Explorer, in the Object construction section of the Activation Tab of your component's properties. So a System Administrator can adjust its value without your having to recompile your class. In this example, we've set it to a connection string, but it could contain any string value you choose.


Protected Overrides Sub Construct(ByVal constructString As String)

        If constructString.Length > 0 Then

            m_strConnectionString = constructString

        End If

End Sub


4-Simulates a call to a stored procedure to add a supplier to the Suppliers table. AutoComplete attribute means if the procedure exits with no exception, then SetComplete is automatically called, otherwise

SetAbort is called.


<AutoCompleteAttribute(True)> _

Public Sub AddSupplier(ByVal CompanyName As String, ByVal Phone As String)


DoTracing("Supplier.AddSupplier called at " & DateTime.Now.ToLongTimeString)

        Catch exp As Exception

            Throw New Exception(exp.Message, exp.InnerException)

        End Try

 End Sub



5-Indicate to COM+ whether the object can be pooled.

Put code here to indicate whether or not you want the object to be pooled at this time.


Protected Overrides Function CanBePooled() As Boolean

        DoTracing("Supplier.CanBePooled called at " & DateTime.Now.ToLongTimeString)

        Return True

End Function


The application has been programmed for Dynamic Registration, which means that the COM+ application the components belong to will automatically be created the first time one of the classes is invoked, provided that the calling application has Administrator privileges. Review the AssemblyInfo file, where the assembly attributes that enable dynamic registration are located.

On the data input form you can add a supplier, by entering a Company Name and Phone and clicking Add Supplier. To update, enter a Company Name, Phone and ID. To delete a supplier, only an ID is needed. If the operation is successful, a message on the status line will indicate that. Working with products is similar.

Note that no database access is performed.  This How-To is focused on illustrating COM+ features.

Each class writes to the Output Window when various events occur, such as instantiation, activation, and deactivation. See the DoTracing procedure in each class. You can uncomment the lines that make it also write to the Event Log. Review these entries to track the life cycle of the components.

Set breakpoints at various places in the classes to see the sequence of events as an object is used in the Enterprise Services environment.



Add Article Comment:
Name :
Email Address :
Comments :
<< How we can implement Parallel Processes in VB.Net

Disclaimer - Privacy
© 2002-2018