How to manually clear a virtual service from a DB

0 Likes

In very rare cases virtual service can get to the state, that it is corrupted and SV Designer, SVM, CLI or any other tool is not able to redeploy/undeploy it.

If this happens to you and you have MS SQL DB, you can use this guide to clean the VS manually. This procedure is however on your own risk.

  1. Stop SV Server
  2. Do DB backup
  3. Do SV Server backup using BackupAndRestore tool
  4. Decide next step based on the DB you have
    1. Any SV supported DB - you can run generic simple script, which supports all DBs, but doesn't print out that many information.
      1. Use attached vs-clear-script-template-generic.txt and replace {VS_ID}, {VS_ID_UNDERSCORES} and {SD_ID} placeholders with appropriate IDs. You can find SD_ID in the VS table. You can use following Powershell command, which would do the replacement for you. Just use your own IDs instead:
        powershell -Command "(gc vs-clear-script-template.txt) -replace '{VS_ID}', '56c82aa4-ee3e-4583-9d93-a2079a0dacb2' -replace '{VS_ID_UNDERSCORES}', '56c82aa4-ee3e-4583-9d93-a2079a0dacb2'.replace('-','_') -replace '{SD_ID}', '27f06902-8c98-460d-ae51-8654530a6b43' | Out-File -encoding ASCII vs-clear-script.sql"
    2. MS SQL - you can choose to run more complex script, which prints out more details about the process:
      1. Use attached vs-clear-script-template-mssql.txt template and replace {VS_ID} and {VS_ID_UNDERSCORES} placeholders with appropriate VS IDs. You can use following Powershell command, which would do that for you. Just use your own ID instead:
        powershell -Command "(gc vs-clear-script-template-mssql.txt) -replace '{VS_ID}', '56c82aa4-ee3e-4583-9d93-a2079a0dacb2' -replace '{VS_ID_UNDERSCORES}', '56c82aa4-ee3e-4583-9d93-a2079a0dacb2'.replace('-','_') | Out-File -encoding ASCII vs-clear-script.sql"
  5. Run generated SQL script on your DB
  6. Start SV Server again

vs-clear-script-template-generic.txt:

/* PERFORM CLEANING START */
DELETE from ACCESS_CONTROL_ENTRY where TYPE='1' and SECURED_RESOURCE_TYPE=1 and (SECURED_RESOURCE_ID in ('{VS_ID}'));
DELETE from SD where ID='{SD_ID}';
DELETE from VS_RUNTIME_CONFIGURATION where VS_ID='{VS_ID}';
DELETE from VS where ID='{VS_ID}';
DELETE from VS_LOGGING_CONFIGURATION where VS_ID='{VS_ID}';

DROP TABLE AML_{VS_ID_UNDERSCORES};
DROP TABLE DM_{VS_ID_UNDERSCORES};
DROP TABLE GEN_{VS_ID_UNDERSCORES};
DROP TABLE LMG_{VS_ID_UNDERSCORES};
DROP TABLE LN_{VS_ID_UNDERSCORES};
DROP TABLE PCM_{VS_ID_UNDERSCORES};
DROP TABLE PM_{VS_ID_UNDERSCORES};
DROP TABLE RAR_{VS_ID_UNDERSCORES};
DROP TABLE RM_{VS_ID_UNDERSCORES};
DROP TABLE RR_{VS_ID_UNDERSCORES};
DROP TABLE SC_{VS_ID_UNDERSCORES};
DROP TABLE LM_{VS_ID_UNDERSCORES};
DROP TABLE DS_{VS_ID_UNDERSCORES};
DROP TABLE LSC_{VS_ID_UNDERSCORES};
/* PERFORM CLEANING END */

vs-clear-script-template-mssql.txt:

/* DECLARATIONS */
DECLARE @VS_ID AS VARCHAR(100)='{VS_ID}';
DECLARE @SD_ID AS VARCHAR(100);
DECLARE @VS_CONFIGURATION_ID AS VARCHAR(100);
DECLARE @CONFIGURATION_ID AS VARCHAR(100);

DECLARE @ACCESS_CONTROL_ENTRY_COUNT AS integer
DECLARE @SD_COUNT AS integer
DECLARE @VS_COUNT AS integer
DECLARE @VS_LOGGING_CONFIGURATION_COUNT AS integer
DECLARE @VS_RUNTIME_CONFIGURATION_COUNT AS integer
DECLARE @VS_DYNAMIC_TABLES_COUNT AS integer

/* GET RELEVANT ROOT IDS */
SELECT @SD_ID=SD_ID from VS where ID=@VS_ID
SELECT @CONFIGURATION_ID=ID from VS_CONFIGURATION where VS_ID=@VS_ID

/* PRINT ROOT IDS */
print 'VS_ID=' + @VS_ID
print 'SD_ID='+ ISNULL(@SD_ID, 'null')
print 'CONFIGURATION_ID='+ ISNULL(@CONFIGURATION_ID, 'null')
print ''

print '= STATS BEFORE ='
/* STATS START */
SELECT @ACCESS_CONTROL_ENTRY_COUNT=count(ID) FROM ACCESS_CONTROL_ENTRY WHERE SECURED_RESOURCE_ID=@VS_ID
SELECT @SD_COUNT=count(ID) FROM SD WHERE ID=@SD_ID
SELECT @VS_COUNT=count(ID) FROM VS WHERE ID=@VS_ID
SELECT @VS_LOGGING_CONFIGURATION_COUNT=count(VS_ID) FROM VS_LOGGING_CONFIGURATION WHERE VS_ID=@VS_ID
SELECT @VS_RUNTIME_CONFIGURATION_COUNT=count(VS_ID) FROM VS_RUNTIME_CONFIGURATION WHERE VS_ID=@VS_ID
SELECT @VS_DYNAMIC_TABLES_COUNT=count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%{VS_ID_UNDERSCORES}%'

print 'ACCESS_CONTROL_ENTRY COUNT=' + CAST(@ACCESS_CONTROL_ENTRY_COUNT as varchar)
print 'SD COUNT=' + CAST(@SD_COUNT as varchar)
print 'VS COUNT=' + CAST(@VS_COUNT as varchar)
print 'VS_LOGGING_CONFIGURATION COUNT=' + CAST(@VS_LOGGING_CONFIGURATION_COUNT as varchar)
print 'VS_RUNTIME_CONFIGURATION COUNT=' + CAST(@VS_RUNTIME_CONFIGURATION_COUNT as varchar)
print 'DYNAMICALLY CREATED TABLES COUNT=' + CAST(@VS_DYNAMIC_TABLES_COUNT as varchar)
/* STATS ENDS */

/* PERFORM CLEANING START */
DELETE from ACCESS_CONTROL_ENTRY where TYPE='1' and SECURED_RESOURCE_TYPE=1 and (SECURED_RESOURCE_ID in (@VS_ID));
DELETE from SD where ID=@SD_ID;
DELETE from VS_RUNTIME_CONFIGURATION where VS_ID=@VS_ID;
DELETE from VS where ID=@VS_ID;
DELETE from VS_LOGGING_CONFIGURATION where VS_ID=@VS_ID;

DROP TABLE AML_{VS_ID_UNDERSCORES};
DROP TABLE DM_{VS_ID_UNDERSCORES};
DROP TABLE GEN_{VS_ID_UNDERSCORES};
DROP TABLE LMG_{VS_ID_UNDERSCORES};
DROP TABLE LN_{VS_ID_UNDERSCORES};
DROP TABLE PCM_{VS_ID_UNDERSCORES};
DROP TABLE PM_{VS_ID_UNDERSCORES};
DROP TABLE RAR_{VS_ID_UNDERSCORES};
DROP TABLE RM_{VS_ID_UNDERSCORES};
DROP TABLE RR_{VS_ID_UNDERSCORES};
DROP TABLE SC_{VS_ID_UNDERSCORES};
DROP TABLE LM_{VS_ID_UNDERSCORES};
DROP TABLE DS_{VS_ID_UNDERSCORES};
DROP TABLE LSC_{VS_ID_UNDERSCORES};
/* PERFORM CLEANING END */

print '= STATS AFTER ='
/* STATS START */
SELECT @ACCESS_CONTROL_ENTRY_COUNT=count(ID) FROM ACCESS_CONTROL_ENTRY WHERE SECURED_RESOURCE_ID=@VS_ID
SELECT @SD_COUNT=count(ID) FROM SD WHERE ID=@SD_ID
SELECT @VS_COUNT=count(ID) FROM VS WHERE ID=@VS_ID
SELECT @VS_LOGGING_CONFIGURATION_COUNT=count(VS_ID) FROM VS_LOGGING_CONFIGURATION WHERE VS_ID=@VS_ID
SELECT @VS_RUNTIME_CONFIGURATION_COUNT=count(VS_ID) FROM VS_RUNTIME_CONFIGURATION WHERE VS_ID=@VS_ID
SELECT @VS_DYNAMIC_TABLES_COUNT=count(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%{VS_ID_UNDERSCORES}%'

print 'ACCESS_CONTROL_ENTRY COUNT=' + CAST(@ACCESS_CONTROL_ENTRY_COUNT as varchar)
print 'SD COUNT=' + CAST(@SD_COUNT as varchar)
print 'VS COUNT=' + CAST(@VS_COUNT as varchar)
print 'VS_LOGGING_CONFIGURATION COUNT=' + CAST(@VS_LOGGING_CONFIGURATION_COUNT as varchar)
print 'VS_RUNTIME_CONFIGURATION COUNT=' + CAST(@VS_RUNTIME_CONFIGURATION_COUNT as varchar)
print 'DYNAMICALLY CREATED TABLES COUNT=' + CAST(@VS_DYNAMIC_TABLES_COUNT as varchar)
/* STATS ENDS */

Labels:

Support Tip
Comment List
Related
Recommended