How to evict a DDC using TSQL

How to evict a DDC using TSQL

book

Article ID: CTX225347

calendar_today

Updated On:

Description

This controller eviction method can be used to evict a controller from the site database without using the SDK.
The only requirement is sysadmin permission to the SQL instance hosting the site database.


Instructions

1 – Using SQL Management studio, connect to the site database and execute the following query to list the controller names and SIDs. Copy the SID of the controller to be removed/evicted:
 
select [sid], SAMName from chb_Config.Controllers cc
join chb_State.Controllers sc on sc.Uid = cc.Uid

2 – In the query below, set @sid variable to the SID value you copied in Step 1 and execute the query against the site DB. Note that this query will only build the eviction statements.
 
Declare @sid varchar(120);
set @sid = 'S-1-5-21-266749940-1637964444-929701000-2643349';
with Remsid(procname) as(
select OBJECT_SCHEMA_NAME(OBJECT_ID) + '.' + [name] from sys.objects
where name = 'RemoveService'
or name = 'RemoveController')
select 'exec ' + procname + ' ' + '''' + @sid + '''' from remsid

3 - The result set needs to be executed against the site DB. The example below will remove the controller with SID 'S-1-5-21-266749940-1637964444-929701000-2643349'.
 
exec chb_State.RemoveController 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec ADIdentitySchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec HostingUnitServiceSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec AppLibrarySchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec DesktopUpdateManagerSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec Monitor.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec StorefrontSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec EnvTestServiceSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec Analytics.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec ConfigurationSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec ConfigLoggingSiteSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec DAS.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec TrustSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'
exec OrchestrationSchema.RemoveService 'S-1-5-21-266749940-1637964444-929701000-2643349'

4 - Remove the entries from table ConfigurationSchema.ServiceInstance for this controller. Example:
 
Delete from ConfigurationSchema.ServiceInstance where ServiceAccountSID = 'S-1-5-21-266749940-1637964444-929701000-2643349'

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.