A downloadable file for this article is available here.
This article is not an introductory article to COM+ or ADO.NET. If you are very new to COM+, I suggest you to go through a previous article of mine that serves as more of an introduction here.
The entire source code for this article is available in the form of a downloadable zip file. The solution was developed using Microsoft Visual Studio 2003 Enterprise Architect with Microsoft SQL Server 2005 Developer Edition on Microsoft Windows Server 2003 Enterprise Edition. Even though I believe that the source code available with this contribution can work with Microsoft Visual Studio.NET 2002, I didn’t really test it in any other environment. I request that you post in the discussion area if you have any problems with execution.
This article is the second of two parts. You can find the first part here.
Setting up the COM+ attributes
For any COM+ applications, you need to set up/configure few of the attributes which would affect your application, together with performance and identity. In our case, the following statements will be necessary to configure the COM+ application:
The first statement is mainly necessary to provide the name of the application. You can also understand that the comment written in the code which looks like an “ApplicationName” attribute specifies the name of the COM+ application that will hold assembly components.
The second statement is mainly necessary to make our COM+ application a server based application. The ApplicationActivation.ActivationOption attribute specifies where the assembly components are loaded on activation. It could be either Library or Server. The option “Library” makes our application run in the consumer/creator’s process. The option “Server” causes our application to be executed in a separate system process (totally different from the consumer/creator’s process).
The third statement is mainly necessary to make our COM+ application strongly signed. The key file (or Assembly key file) specifies the name of the strong key that will be used to sign the assembly. The sink file must be generated using “sn.exe” as follows:
sn -k CoreMSSQLDataAccessHelper.snk
Every COM+ application is equipped with its own security features by default. To work with default security features, the fourth statement is necessary. There exist several options for security. It may be necessary to deal with a few of them based on your application requirements.
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."), _
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:
' 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.
Before proceeding further you may need to understand the issue of the “ConnectingString.” I made it simple to provide the “ConnectionString” as follows: