Completing Your Own SQL Server Based Data Access Helper using COM+ and VB.NET - Customizing the COM class a bit
(Page 2 of 6 )
It may be necessary to customize the definition of the COM+ class a bit according to our requirements. Let us consider the following definition, which I modified for our application:
<ConstructionEnabled([Default]:="Connection String is not implemented from this point."), _
Transaction(TransactionOption.Supported), _
JustInTimeActivation(True), Serializable(), _
ObjectPooling(MinPoolSize:=5, MaxPoolSize:=25, CreationTimeout:=20000), _
ComponentAccessControl(), SecurityRole("Administrator"), SecurityRole("User", SetEveryoneAccess:=True)> _
PublicClass CDataAccess
Inherits ServicedComponent
By nature, a COM+ would be quite different from any normal OOP based class. The first attribute in the above definition is the “ConstructionEnabled” attribute. This is generally used to provide database related “connection string” information or other configuration options. At this moment, I didn’t really make use of “connectionstring” from this attribute. That is why I wrote a small comment there.
If you really wanted to implement the connection string through configuration properties, you may need to modify the code as follows:
ProtectedOverrides Sub Construct(ByVal constructString As String)
' Construct method will be called after the New method
m_ConnectionString = constructString
EndSub
The class level variable m_ConnectionString would hold the connection string you specified in the configuration properties of the COM+ application.
The second attribute is the “Transaction” attribute. A COM+ application may or may not need to support any transactions. But, as we are developing a data access helper, it may be necessary to have a COM+ application with transaction support.
Further, I defined “JustInTimeActivation,” “Serializable” and “ObjectPooling.” Those are essential for performance. You can customize them according to your requirements.
Customization of the roles of security is possible through the “SecurityRole” attribute. And last but not least, every COM+ class must inherit from the class “ServicedComponent” available in “System.EnterpriseServices” namespace.
Next: Getting a row of data from the database using a single method >>
More MS SQL Server Articles
More By Jagadish Chaterjee