remove the scope and re-provision... use this code to remove a scope
private void RemoveScope(SqlConnection Conn, bool ShowAlert)
{
foreach (var table in _settings.TablesToSync)
{
SqlCommand dropTracking = new SqlCommand(@"
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_tracking]') AND type in (N'U'))
DROP TABLE [dbo].[" + table.Key + "_tracking]", Conn);
dropTracking.ExecuteNonQuery();
SqlCommand dropTriggers = new SqlCommand(@"
IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_delete_trigger]'))
DROP TRIGGER [dbo].[" + table.Key + @"_delete_trigger];
IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_insert_trigger]'))
DROP TRIGGER [dbo].[" + table.Key + @"_insert_trigger];
IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_update_trigger]'))
DROP TRIGGER [dbo].[" + table.Key + @"_update_trigger];
", Conn);
dropTriggers.ExecuteNonQuery();
SqlCommand dropStoredProc = new SqlCommand(@"
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_delete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_delete];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_deletemetadata]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_deletemetadata];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_insert]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_insert];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_insertmetadata]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_insertmetadata];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_selectchanges]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_selectchanges];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_selectrow]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_selectrow];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_update]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_update];
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[" + table.Key + @"_updatemetadata]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[" + table.Key + @"_updatemetadata];
", Conn);
dropStoredProc.ExecuteNonQuery();
}
SqlCommand getScopeGuid = new SqlCommand(@"
USE [" + Conn.Database + @"]
SELECT scope_config_id FROM scope_info WHERE scope_name = '" + _settings.ScopeName + "'", Conn);
var reader = getScopeGuid.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
var id = reader.GetGuid(0);
reader.Close();
SqlCommand deleteScope = new SqlCommand(@"
DELETE FROM scope_info WHERE scope_config_id = '" + id + @"';
DELETE FROM scope_config WHERE config_id = '" + id + @"';
", Conn);
deleteScope.ExecuteNonQuery();
}
if(ShowAlert)
MessageBox.Show("Scope has been removed");
}