PRB: COM+ Catalog Order of SaveChanges Affects Role Assignment (272100)



The information in this article 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.

MORE INFORMATION

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.
  1. Replace MyDll in the script with your component.
  2. 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 "Starting"
    
    Set catalog = CreateObject("COMAdmin.COMAdminCatalog")
    
    set apps=catalog.GetCollection("Applications") 
    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 = "BUGTester" Then
          apps.Remove(I)
        End If
    Next
    
    apps.SaveChanges()
    
    'Add a new application "BUGTester".
    apps.Populate()
    set app = apps.Add()
    
    app.Value("Name")= "BUGTester"
    apps.SaveChanges()
    
    'Add a new role to the application.
    set roles = apps.GetCollection("Roles", app.Key)
    set role = roles.Add()
    role.Value("Name")= "Tester"
    roles.SaveChanges()
    
    'Add a component. Replace c:\MyDll.dll with a DLL that contains a component.
    catalog.InstallComponent "BUGTester", "c:\MyDll.dll", "", ""
    
    Set components = apps.GetCollection("Components", app.Key)
    components.Populate()
    components.Item(0).Value("Description") = "Test"
    
    'To reproduce this bug, comment out the following line. 
    components.SaveChanges()
    
    Set componentRoles = components.GetCollection("RolesForComponent", components.Item(0).Key)
    Set componentRole = componentRoles.Add()
    componentRole.Value("Name") = "Tester"
    componentRoles.SaveChanges()
    
    components.SaveChanges()
    
    WScript.Echo "Test End"
    
    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
    					
  3. 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.

Modification Type:MajorLast Reviewed:2/21/2002
Keywords:kbDSupport kbprb kbSysAdmin KB272100