Microsoft KB Archive/246138

= How To Using COM+ 1.0 Constructor Strings from Visual Basic =

Article ID: 246138

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft COM+ 1.0

-



This article was previously published under Q246138



SUMMARY
COM+ 1.0 Provides the ability to administratively specify a string that will be passed to your object just after its creation and before any other method is invoked. This article explains how to specify this string and how to retrieve it in your object.



MORE INFORMATION
To specify a constructor string:


 * 1) Make sure your object is configured within a COM+ application.
 * 2) In the Component Services snap-in navigate to your component by right-clicking the component and selecting Properties.
 * 3) In the Activation tab select "Enable Object Construction" and type the string in the Constructor String text box. This may be a DSN, the name of some computer or queue, or some other information that your application needs to function that is administration-related.

To retrieve this string in your object, it must expose a certain interface called IObjectConstruct. To do so:

 Make sure your project has a reference to "COM+ 1.0 Services Type Library".  In your class module, beneath any Option statements, add the following line of code: Implements IObjectConstruct

You may also add a private class-level variable to hold the string: Private msConstructorString As String  In the scope list box in your code editor, where it reads "(General)", you should have a new item called IObjectConstruct. When you select it the IObjectConstruct_Construct function will be added to your class.  Add the following code to it so the function looks as follows: Private Sub IObjectConstruct_Construct(ByVal pCtorObj As Object) msConstructorString = pCtorObj.ConstructString End Sub This retrieves the ConstructString and stores it in your private variable. 

NOTE: By default, constructor strings are not considered "secure" because any computer in the domain could read them. Therefore, we do not recommend that you store passwords in constructor strings (such as those found in complete construction strings). As an alternative, you can use UDL files to store database connection strings. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

189680 How To Use Data Link Files with ADO

