Add new users in SSAS security

一曲冷凌霜 提交于 2019-12-20 02:36:12

问题


I want to add users in SSAS security using following XMLA script.

DECLARE @CreateUserInSsasXMLA VARCHAR(MAX) = 
        '<Batch AllowCreate="true" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" Transaction="true">            
            <Alter ObjectExpansion="ObjectProperties" xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
            <Object />
              <Object>
                <RoleID>Administrators</RoleID>
              </Object>
              <ObjectDefinition>
                <Role xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200="http://schemas.microsoft.com/analysisservices/2010/engine/200" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" xmlns:ddl300="http://schemas.microsoft.com/analysisservices/2011/engine/300" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300" xmlns:ddl400="http://schemas.microsoft.com/analysisservices/2012/engine/400" xmlns:ddl400_400="http://schemas.microsoft.com/analysisservices/2012/engine/400/400">
                  <ID>Administrators</ID>
                  <Name>Administrators</Name>
                  <Members>        
                    <Member>
                      <Name>'+@UserID+'</Name>
                    </Member>        
                  </Members>
                </Role>
              </ObjectDefinition>
            </Alter>
            </Batch>
            '
            IF  @UserID <> 'Dummy_User'
            BEGIN               
                BEGIN TRY           
                    EXEC (@CreateUserInSsasXMLA) At AdminCPM;
                    PRINT 'User ' + @UserID + ' has been created.'
                END TRY
                BEGIN CATCH
                    PRINT 'Something went wrong while creating user ' + @UserID
                END CATCH
            END
            ELSE
            BEGIN
                PRINT 'Either Server Name or User Name or both parameter not specified.'
            END     

It works fine and it's able to add new user in SSAS. But the problem is, it's also deleting all existing users. How to fix this? I want to have all the existing users plus the new one.


回答1:


If you install ASSP then you can run the following SQL query which calls an ASSP sproc to get the list of current members. Once this completes, you can append @oldMembers to your existing XMLA:

declare @members table (Sid varchar(1000), Name varchar(1000), Parent_RoleID varchar(1000), Parent_DatabaseID varchar(1000))

insert @members
EXECUTE('CALL ASSP.DiscoverXmlMetadata("\Database\Roles\Role\Members\Member")') at AdminCPM

declare @oldMembers varchar(max) = ''
select @oldMembers = @oldMembers + '<Member><Name>'+Name+'</Name></Member>
'
from @members


来源:https://stackoverflow.com/questions/31422425/add-new-users-in-ssas-security

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!