Microsoft KB Archive/272100

= PRB: COM+ Catalog Order of SaveChanges Affects Role Assignment =

Article ID: 272100

Article Last Modified on 2/21/2002

-

APPLIES TO


 * Microsoft COM+ 1.0

-



This article was previously published under Q272100



SYMPTOMS
When you assign roles to components through the catalog admin automation objects, changes may not be saved if the SaveChanges method is not called on components before the ComponentRoles.



CAUSE
When you retrieve the ComponentRoles from the components, you get them directly from the catalog and not from the cached components table. The saved changes to the ComponentRoles are overwritten when the cached components table is saved. If you save changes to the components table before you get the ComponentRoles, the last call to components.SaveChanges effectively does nothing because nothing has been modified in the components table.



RESOLUTION
To resolve this problem, call SaveChanges on the components before you call SaveChanges on the ComponentRoles.



Steps to Reproduce Behavior
NOTE: To reproduce the behavior according to these steps, you must have a dynamic-link library (DLL) with a Component Object Model (COM) component that you can install with the script.  Replace MyDll in the script with your component.  In Notepad, paste the following code, and give the file a .vbs extension: Dim catalog Dim apps Dim app Dim roles Dim role Dim components Dim component Dim componentRoles Dim componentRole

WScript.Echo &quot;Starting&quot;

Set catalog = CreateObject(&quot;COMAdmin.COMAdminCatalog&quot;)

set apps=catalog.GetCollection(&quot;Applications&quot;) apps.Populate lNumApps = apps.Count

'If test App already exists, remove it. For I = lNumApps - 1 to 0 step -1 Set app = apps.Item(I) If app.Name = &quot;BUGTester&quot; Then apps.Remove(I) End If Next

apps.SaveChanges

'Add a new application &quot;BUGTester&quot;. apps.Populate set app = apps.Add

app.Value(&quot;Name&quot;)= &quot;BUGTester&quot; apps.SaveChanges

'Add a new role to the application. set roles = apps.GetCollection(&quot;Roles&quot;, app.Key) set role = roles.Add role.Value(&quot;Name&quot;)= &quot;Tester&quot; roles.SaveChanges

'Add a component. Replace c:\MyDll.dll with a DLL that contains a component. catalog.InstallComponent &quot;BUGTester&quot;, &quot;c:\MyDll.dll&quot;, &quot;&quot;, &quot;&quot;

Set components = apps.GetCollection(&quot;Components&quot;, app.Key) components.Populate components.Item(0).Value(&quot;Description&quot;) = &quot;Test&quot;

'To reproduce this bug, comment out the following line. components.SaveChanges

Set componentRoles = components.GetCollection(&quot;RolesForComponent&quot;, components.Item(0).Key) Set componentRole = componentRoles.Add componentRole.Value(&quot;Name&quot;) = &quot;Tester&quot; componentRoles.SaveChanges

components.SaveChanges

WScript.Echo &quot;Test End&quot;

set catalog=Nothing set apps=Nothing set app=Nothing set roles=Nothing set role=Nothing set components=Nothing set component=Nothing set componentRoles=Nothing set componentRole=Nothing  When you comment out the indicated line, the Role check box on the Security tab of the components properties is cleared. However, if the line is not commented out, the Role check box is selected.

Keywords: kbsysadmin kbprb KB272100

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.