From 46a70899bd1e2cd1142866df907e37e684d0d534 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 20 Nov 2013 22:58:38 +0000 Subject: [PATCH] Add code to stop the process of loading data and notify the user when there is a problem with the 16-bit data, especially proc.ini files. Added improvements to the code to better handle proc.ini files when they are part of a multi unit site, especially case sensitivity of elements of the proc.ini file. The changes involve all of the stored procedures, functions and table changes to support multiuser and security configuration of PROMS. --- PROMS/DataLoader/LoadTreeDB.cs | 80 ++- PROMS/DataLoader/Loader.cs | 7 +- PROMS/DataLoader/PROMSFixes.Sql | 1105 +++++++++++++++++++++++++++++++ 3 files changed, 1182 insertions(+), 10 deletions(-) diff --git a/PROMS/DataLoader/LoadTreeDB.cs b/PROMS/DataLoader/LoadTreeDB.cs index 36f6ae57..3d5e5fca 100644 --- a/PROMS/DataLoader/LoadTreeDB.cs +++ b/PROMS/DataLoader/LoadTreeDB.cs @@ -113,6 +113,8 @@ namespace DataLoader XmlDocument d = cfg.IniToXml(vb.Path + "\\proc.ini"); AddSlaveUnits(d, vb.Path); + if (frmMain.ProcessFailed) + return null; //DocVersionConfig fld_cfg = new DocVersionConfig(d == null ? "" : d.InnerXml); FolderConfig fld_cfg = (d==null)?null:new FolderConfig(d.InnerXml); // translate curset.dat into xml & add to d (somehow). @@ -166,10 +168,21 @@ namespace DataLoader private void AddSlaveUnits(XmlDocument d, string path) { string masterDir = GetMasterDir(d); - if (masterDir == null) return; + if (masterDir == null) + { + //not a master slave procedure set + return; + } DirectoryInfo master = new DirectoryInfo(path); if (master.Name.ToUpper() != masterDir.ToUpper()) return; List names = GetUnitNames(d); + if (names == null) + { + frmMain.ProcessFailed = true; + MessageBox.Show("Could not find Unit names in slave proc.ini files"); + frmMain.MyError = "Could not find Unit names in slave proc.ini files"; + return; + } DirectoryInfo[] slaves = master.Parent.GetDirectories(masterDir.ToUpper().Replace(".PRC",".SL*")); XmlDocument units = new XmlDocument(); units.LoadXml(""); @@ -184,11 +197,18 @@ namespace DataLoader XmlDocument xSlave = cfg.IniToXml(ini.FullName); xSlave.LoadXml(xSlave.OuterXml.Replace(" GetUnitNames(XmlDocument d) { - XmlNode zapp = d.SelectSingleNode("//Unit"); + XmlNode zapp = GetXMLNode(d, "Unit");// d.SelectSingleNode("//Unit"); if (zapp == null) return null; - XmlNode zmstr = zapp.Attributes.GetNamedItem("Name"); + XmlNode zmstr = GetXMLAttribute(zapp, "Name");// zapp.Attributes.GetNamedItem("Name"); if (zmstr == null) return null; string[] names = zmstr.InnerText.Split(",".ToCharArray()); return new List(names); @@ -226,9 +286,9 @@ namespace DataLoader private static string GetMasterDir(XmlDocument d) { - XmlNode zapp = d.SelectSingleNode("//Applicability"); + XmlNode zapp = GetXMLNode(d, "Applicability");// d.SelectSingleNode("//Applicability"); if (zapp == null) return null; - XmlNode zmstr = zapp.Attributes.GetNamedItem("MasterDir"); + XmlNode zmstr = GetXMLAttribute(zapp, "MasterDir");// zapp.Attributes.GetNamedItem("MasterDir"); if (zmstr == null) return null; return zmstr.InnerText; } @@ -277,6 +337,8 @@ namespace DataLoader { TreeNode tnc = tn.Nodes.Add(vbc.Title); object idc = cslaObject(vbc, dbConn, parent, tnc); + if (frmMain.ProcessFailed) + return; frmMain.Status = "Loading " + vbc.Title; MigrateChildren(vbc, vs, dbConn, idc, tnc); } diff --git a/PROMS/DataLoader/Loader.cs b/PROMS/DataLoader/Loader.cs index 8f994444..50a38d2d 100644 --- a/PROMS/DataLoader/Loader.cs +++ b/PROMS/DataLoader/Loader.cs @@ -129,12 +129,15 @@ namespace DataLoader vlnServer vs = new vlnServer(); frmMain.Status = "Loading " + fldr.Name; MigrateChildren(vb, vs, dbConn, fldr, tn); + if (frmMain.ProcessFailed) + return false; tn.Expand(); } } catch (Exception ex) { - log.ErrorFormat("Could not load data, error = {0}", ex.Message); + log.Error("Error in LoadFolders", ex); +// log.ErrorFormat("Could not load data, error = {0}", ex.Message); //return false; throw new Exception("Error in LoadFolders", ex); } @@ -166,6 +169,8 @@ namespace DataLoader vlnServer vs = new vlnServer(); frmMain.Status = "Loading " + fldr.Name; MigrateChildren(vb, vs, dbConn, fldr, tn); + if (frmMain.ProcessFailed) + return false; tn.Expand(); } } diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index ca82a08f..283394d9 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -7071,3 +7071,1108 @@ declare @CMD varchar(max) set @CMD = 'ALTER DATABASE [' + db_name() +'] SET AUTO_SHRINK OFF' exec(@CMD) GO + +--added by JCB for Security and MultiUser support +--ALTER TABLE Sessions add MachineName and ProcessID columns if they do not exist +IF COL_LENGTH('Sessions','MachineName') IS NULL + ALTER TABLE Sessions ADD [MachineName] [nvarchar](100) NOT NULL,[ProcessID] [int] NOT NULL; +GO +--ALTER TABLE Sessions change DTSActivity column to not null +ALTER TABLE sessions ALTER COLUMN [DTSActivity] [datetime] NOT NULL +GO +--ALTER TABLE Sessions set DTSActivity column default value to getdate() +IF OBJECT_ID('DF_Sessions_DTSActivity', 'D') IS NULL + ALTER TABLE sessions ADD CONSTRAINT [DF_Sessions_DTSActivity] DEFAULT (getdate()) for [DTSActivity]; +GO + +/****** Object: StoredProcedure [purgeData] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[purgeData]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [purgeData]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[purgeData] + +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + delete from [AnnotationAudits] + dbcc checkident([AnnotationAudits],reseed,0) + delete from [Applicabilities] + dbcc checkident([Applicabilities],reseed,0) + delete from [ApplicableStructures] + delete from [Assignments] + dbcc checkident([Assignments],reseed,0) + delete from [Associations] + dbcc checkident([Associations],reseed,0) + delete from [Checks] + dbcc checkident([Checks],reseed,0) + delete from [ContentAudits] + dbcc checkident([ContentAudits],reseed,0) + delete from [DeleteLog] + dbcc checkident([DeleteLog],reseed,0) + delete from [Details] + dbcc checkident([Details],reseed,0) + delete from [DocumentAudits] + dbcc checkident([DocumentAudits],reseed,0) + delete from [DocVersions] + dbcc checkident([DocVersions],reseed,0) + delete from [DROUsages] + dbcc checkident([DROUsages],reseed,0) + delete from [EntryAudits] + dbcc checkident([EntryAudits],reseed,0) + delete from [Figures] + dbcc checkident([Figures],reseed,0) + delete from [Folders] + dbcc checkident([Folders],reseed,0) + delete from [GridAudits] + dbcc checkident([GridAudits],reseed,0) + delete from [ImageAudits] + dbcc checkident([ImageAudits],reseed,0) + delete from [ItemAudits] + dbcc checkident([ItemAudits],reseed,0) + delete from [Memberships] + dbcc checkident([Memberships],reseed,0) + delete from [PartAudits] + dbcc checkident([PartAudits],reseed,0) + delete from [Pdfs] + delete from [Permissions] + dbcc checkident([Permissions],reseed,0) + delete from [ROFsts] + dbcc checkident([ROFsts],reseed,0) + delete from [ROImages] + dbcc checkident([ROImages],reseed,0) + delete from [Roles] + dbcc checkident([Roles],reseed,0) + delete from [ROUsageAudits] + dbcc checkident([ROUsageAudits],reseed,0) + delete from [tblAnnotations] + dbcc checkident([tblAnnotations],reseed,0) + delete from [tblEntries] + delete from [tblGrids] + delete from [tblImages] + delete from [tblParts] + delete from [tblROUsages] + dbcc checkident([tblROUsages],reseed,0) + delete from [TransitionAudits] + dbcc checkident([TransitionAudits],reseed,0) + delete from [Users] + dbcc checkident([Users],reseed,0) + delete from [Versions] + dbcc checkident([Versions],reseed,0) + delete from [ZContents] + delete from [ZTransitions] + delete from [AnnotationTypes] + dbcc checkident([AnnotationTypes],reseed,0) + delete from [Connections] + dbcc checkident([Connections],reseed,0) + delete from [Groups] + dbcc checkident([Groups],reseed,0) + delete from [Revisions] + dbcc checkident([Revisions],reseed,0) + delete from [RODbs] + dbcc checkident([RODbs],reseed,0) + delete from [Stages] + dbcc checkident([Stages],reseed,0) + delete from [tblDocuments] + dbcc checkident([tblDocuments],reseed,0) + delete from [tblTransitions] + dbcc checkident([tblTransitions],reseed,0) + delete from [tblItems] + dbcc checkident([tblItems],reseed,0) + delete from [tblContents] + dbcc checkident([tblContents],reseed,0) + delete from [Formats] + dbcc checkident([Formats],reseed,0) + delete from [Sessions] + dbcc checkident([Sessions],reseed,0) + delete from [Owners] + dbcc checkident([Owners],reseed,0) + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: purgeData Succeeded' +ELSE PRINT 'Procedure Creation: purgeData Error on Creation' +GO + +/****** Object: StoredProcedure [getSessions] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getSessions]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getSessions]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getSessions] + +WITH EXECUTE AS OWNER +AS + SELECT + [SessionID], + [UserID], + [DTSDtart], + [DTSEnd], + [DTSActivity], + [LastChanged], + [MachineName], + [ProcessID] + FROM [Sessions] + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getSessions Succeeded' +ELSE PRINT 'Procedure Creation: getSessions Error on Creation' +GO + +/****** Object: StoredProcedure [updateSession] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updateSession]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [updateSession]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[updateSession] + +( + @SessionID int, + @UserID nvarchar(100), + @DTSDtart datetime, + @DTSEnd datetime=null, + @DTSActivity datetime, + @LastChanged timestamp, + @MachineName nvarchar(100), + @ProcessID int, + @newLastChanged timestamp output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + UPDATE [Sessions] + SET + [UserID]=@UserID, + [DTSDtart]=@DTSDtart, + [DTSEnd]=@DTSEnd, + [DTSActivity]=@DTSActivity, + [MachineName]=@MachineName, + [ProcessID]=@ProcessID + WHERE [SessionID]=@SessionID AND [LastChanged]=@LastChanged + IF @@ROWCOUNT = 0 + BEGIN + IF NOT exists(select * from [Sessions] WHERE [SessionID]=@SessionID) + RAISERROR('Session record has been deleted by another user', 16, 1) + ELSE + RAISERROR('Session has been edited by another user', 16, 1) + END + + SELECT @newLastChanged=[LastChanged] + FROM [Sessions] WHERE [SessionID]=@SessionID + + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: updateSession Succeeded' +ELSE PRINT 'Procedure Creation: updateSession Error on Creation' +GO + +/****** Object: StoredProcedure [addSession] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addSession]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [addSession]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[addSession] + +( + @UserID nvarchar(100), + @DTSDtart datetime, + @DTSEnd datetime=null, + @DTSActivity datetime, + @MachineName nvarchar(100), + @ProcessID int, + @newSessionID int output, + @newLastChanged timestamp output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + INSERT INTO [Sessions] + ( + [UserID], + [DTSDtart], + [DTSEnd], + [DTSActivity], + [MachineName], + [ProcessID] + ) + VALUES + ( + @UserID, + @DTSDtart, + @DTSEnd, + @DTSActivity, + @MachineName, + @ProcessID + ) + SELECT @newSessionID= SCOPE_IDENTITY() + SELECT @newLastChanged=[LastChanged] + FROM [Sessions] WHERE [SessionID]=@newSessionID + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: addSession Succeeded' +ELSE PRINT 'Procedure Creation: addSession Error on Creation' +GO + +/****** Object: StoredProcedure [deleteSession] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteSession]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [deleteSession]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[deleteSession] + +( + @SessionID int +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + DELETE [Sessions] + WHERE [SessionID] = @SessionID + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: deleteSession Succeeded' +ELSE PRINT 'Procedure Creation: deleteSession Error on Creation' +GO + +/****** Object: StoredProcedure [getSession] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getSession]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getSession]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getSession] + +( + @SessionID int +) +WITH EXECUTE AS OWNER +AS + SELECT + [SessionID], + [UserID], + [DTSDtart], + [DTSEnd], + [DTSActivity], + [LastChanged], + [MachineName], + [ProcessID] + FROM [Sessions] + WHERE [SessionID]=@SessionID + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getSession Succeeded' +ELSE PRINT 'Procedure Creation: getSession Error on Creation' +GO + +/****** Object: StoredProcedure [existsSession] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[existsSession]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [existsSession]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[existsSession] + +( + @SessionID int +) +WITH EXECUTE AS OWNER +AS + SELECT COUNT(*) + FROM [Sessions] WHERE [SessionID]=@SessionID + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: existsSession Succeeded' +ELSE PRINT 'Procedure Creation: existsSession Error on Creation' +GO + +/****** Object: StoredProcedure [vesp_SessionCleanup] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SessionBegin]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_SessionBegin]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[vesp_SessionBegin] + +( + @UserID nvarchar(100), + @MachineName nvarchar(100), + @ProcessID int +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + --delete old closed sessions + DELETE FROM Sessions WHERE UserID = @UserID and DTSEnd is not null + --delete old owners from inactive sessions + DELETE FROM Owners WHERE SessionID in (SELECT SessionID FROM Sessions WHERE UserID = @UserID and DTSEnd is null and DTSActivity < DATEADD(minute, -15, getdate())) + --delete inactive sessions where last activity is before 15 minutes ago + DELETE FROM Sessions WHERE UserID = @UserID and DTSEnd is null and DTSActivity < DATEADD(minute, -15, getdate()) + INSERT INTO [Sessions]([UserID],[MachineName],[ProcessID]) + VALUES (@UserID, @MachineName, @ProcessID) + SELECT + [SessionID], + [UserID], + [DTSDtart], + [DTSEnd], + [DTSActivity], + [LastChanged], + [MachineName], + [ProcessID] + FROM [Sessions] + WHERE [SessionID]=SCOPE_IDENTITY() + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SessionBegin Succeeded' +ELSE PRINT 'Procedure Creation: vesp_SessionBegin Error on Creation' +GO + +/****** Object: StoredProcedure [vesp_SessionPing] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SessionPing]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_SessionPing]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE vesp_SessionPing +( + @SessionID int +) +WITH EXECUTE AS OWNER +AS +BEGIN + --update active session dtsactivity value + UPDATE Sessions SET DTSActivity = getdate() WHERE SessionID = @SessionID +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SessionPing Succeeded' +ELSE PRINT 'Procedure Creation: vesp_SessionPing Error on Creation' +GO + +/****** Object: StoredProcedure [vesp_SessionPing] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SessionEnd]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_SessionEnd]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE vesp_SessionEnd +( + @SessionID int +) +WITH EXECUTE AS OWNER +AS +BEGIN + --delete unclosed owners for session being closed + DELETE FROM Owners WHERE SessionID = @SessionID + --update active session dtsend value + UPDATE Sessions SET DTSEnd = getdate() WHERE SessionID = @SessionID +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SessionEnd Succeeded' +ELSE PRINT 'Procedure Creation: vesp_SessionEnd Error on Creation' +GO + +/****** Object: StoredProcedure [getOwners] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getOwners]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getOwners]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getOwners] + +WITH EXECUTE AS OWNER +AS + SELECT + [OwnerID], + [SessionID], + [OwnerType], + [OwnerItemID], + [DTSStart], + [LastChanged] + FROM [Owners] + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getOwners Succeeded' +ELSE PRINT 'Procedure Creation: getOwners Error on Creation' +GO + +/****** Object: StoredProcedure [getOwnersBySessionID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getOwnersBySessionID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getOwnersBySessionID]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getOwnersBySessionID] +( + @SessionID int +) + +WITH EXECUTE AS OWNER +AS + SELECT + [OwnerID], + [SessionID], + [OwnerType], + [OwnerItemID], + [DTSStart], + [LastChanged] + FROM [Owners] + WHERE [SessionID] = @SessionID + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getOwnersBySessionID Succeeded' +ELSE PRINT 'Procedure Creation: getOwnersBySessionID Error on Creation' +GO + +/****** Object: StoredProcedure [updateOwner] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[updateOwner]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [updateOwner]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[updateOwner] + +( + @OwnerID int, + @SessionID int, + @OwnerType tinyint, + @OwnerItemID int, + @DTSStart datetime, + @LastChanged timestamp, + @newLastChanged timestamp output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + UPDATE [Owners] + SET + [SessionID]=@SessionID, + [OwnerType]=@OwnerType, + [OwnerItemID]=@OwnerItemID, + [DTSStart]=@DTSStart + WHERE [OwnerID]=@OwnerID AND [LastChanged]=@LastChanged + IF @@ROWCOUNT = 0 + BEGIN + IF NOT exists(select * from [Owners] WHERE [OwnerID]=@OwnerID) + RAISERROR('Owner record has been deleted by another user', 16, 1) + ELSE + RAISERROR('Owner has been edited by another user', 16, 1) + END + + SELECT @newLastChanged=[LastChanged] + FROM [Owners] WHERE [OwnerID]=@OwnerID + + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: updateOwner Succeeded' +ELSE PRINT 'Procedure Creation: updateOwner Error on Creation' +GO + +/****** Object: StoredProcedure [addOwner] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[addOwner]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [addOwner]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[addOwner] + +( + @SessionID int, + @OwnerType tinyint, + @OwnerItemID int, + @DTSStart datetime, + @newOwnerID int output, + @newLastChanged timestamp output +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + INSERT INTO [Owners] + ( + [SessionID], + [OwnerType], + [OwnerItemID], + [DTSStart] + ) + VALUES + ( + @SessionID, + @OwnerType, + @OwnerItemID, + @DTSStart + ) + SELECT @newOwnerID= SCOPE_IDENTITY() + SELECT @newLastChanged=[LastChanged] + FROM [Owners] WHERE [OwnerID]=@newOwnerID + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: addOwner Succeeded' +ELSE PRINT 'Procedure Creation: addOwner Error on Creation' +GO + +/****** Object: StoredProcedure [deleteOwner] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[deleteOwner]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [deleteOwner]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[deleteOwner] + +( + @OwnerID int +) +WITH EXECUTE AS OWNER +AS +BEGIN TRY -- Try Block + BEGIN TRANSACTION + DELETE [Owners] + WHERE [OwnerID] = @OwnerID + IF( @@TRANCOUNT > 0 ) COMMIT +END TRY +BEGIN CATCH -- Catch Block + IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level + ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback + EXEC vlnErrorHandler +END CATCH +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: deleteOwner Succeeded' +ELSE PRINT 'Procedure Creation: deleteOwner Error on Creation' +GO + +/****** Object: StoredProcedure [getOwner] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getOwner]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getOwner]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getOwner] + +( + @OwnerID int +) +WITH EXECUTE AS OWNER +AS + SELECT + [OwnerID], + [SessionID], + [OwnerType], + [OwnerItemID], + [DTSStart], + [LastChanged] + FROM [Owners] + WHERE [OwnerID]=@OwnerID + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getOwner Succeeded' +ELSE PRINT 'Procedure Creation: getOwner Error on Creation' +GO + +/****** Object: StoredProcedure [existsOwner] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[existsOwner]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [existsOwner]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[existsOwner] + +( + @OwnerID int +) +WITH EXECUTE AS OWNER +AS + SELECT COUNT(*) + FROM [Owners] WHERE [OwnerID]=@OwnerID + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: existsOwner Succeeded' +ELSE PRINT 'Procedure Creation: existsOwner Error on Creation' +GO + +/****** Object: StoredProcedure [vesp_SessionCanCheckOutItem] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SessionCanCheckOutItem]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_SessionCanCheckOutItem]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +/* +exec dbo.vesp_SessionCanCheckOutItem 25915,0 +exec dbo.vesp_SessionCanCheckOutItem 554,1 +exec dbo.vesp_SessionCanCheckOutItem 13,2 +*/ +CREATE PROCEDURE [dbo].[vesp_SessionCanCheckOutItem] +( + @ObjectID int, + @ObjectType int +) +WITH EXECUTE AS OWNER +AS +BEGIN + DECLARE @CheckOuts TABLE + ( + SessionID int + ) +--look to see if object is already checked out in owner table as passed object type + INSERT INTO @CheckOuts SELECT DISTINCT SessionID FROM Owners WHERE OwnerItemID = @ObjectID AND OwnerType = @ObjectType +--look to see if object is part of a checked out docversion as passed object type + DECLARE @VersionIDList varchar(max) + SELECT @VersionIDList = COALESCE(@VersionIDList + ',','') + CAST(OwnerItemID as varchar(4)) FROM Owners WHERE OwnerType = 2 + IF ISNULL(@VersionIDList,'') != '' AND @ObjectType = 0 BEGIN --procedure + INSERT INTO @CheckOuts + SELECT ss.SessionID FROM dbo.vefn_GetVersionItems(@VersionIDList) vi + INNER JOIN Contents cc ON vi.ContentID = cc.ContentID + INNER JOIN Owners oo ON vi.VersionID = oo.OwnerItemID + INNER JOIN Sessions ss ON oo.SessionID = ss.SessionID + WHERE cc.Type = 0 AND vi.ItemID = @ObjectID + END + IF ISNULL(@VersionIDList,'') != '' AND @ObjectType = 1 BEGIN --document + INSERT INTO @CheckOuts + SELECT ss.SessionID FROM dbo.vefn_GetVersionItems(@VersionIDList) vi + INNER JOIN Contents cc ON vi.ContentID = cc.ContentID + INNER JOIN Entries ee ON vi.ContentID = ee.ContentID + INNER JOIN Owners oo ON vi.VersionID = oo.OwneritemID + INNER JOIN Sessions ss ON oo.SessionID = ss.SessionID + WHERE ee.DocID = @ObjectID + END +--look to see if object type is docversion that no part of docversion passed is checked out + IF @ObjectType = 2 BEGIN + --see what procedures maybe checked out + INSERT INTO @CheckOuts + SELECT ss.SessionID FROM dbo.vefn_GetVersiONItems(@ObjectID) vi + INNER JOIN Contents cc ON vi.ContentID = cc.ContentID + INNER JOIN Owners oo ON vi.ItemID = oo.OwnerItemID + INNER JOIN Sessions ss ON oo.SessionID = ss.SessionID + WHERE cc.Type = 0 + --see what documents maybe checked out + INSERT INTO @CheckOuts + SELECT ss.SessionID FROM dbo.vefn_GetVersiONItems(@ObjectID) vi + INNER JOIN Contents cc ON vi.ContentID = cc.ContentID + INNER JOIN Entries ee ON vi.ContentID = ee.ContentID + INNER JOIN Owners oo ON ee.DocID = oo.OwnerItemID + INNER JOIN Sessions ss ON oo.SessionID = ss.SessionID + END + + SELECT + [SessionID], + [UserID], + [DTSDtart], + [DTSEnd], + [DTSActivity], + [LastChanged], + [MachineName], + [ProcessID] + FROM [Sessions] + WHERE [SessionID] IN (SELECT SessionID FROM @CheckOuts) +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SessionCanCheckOutItem Succeeded' +ELSE PRINT 'Procedure Creation: vesp_SessionCanCheckOutItem Error on Creation' +GO + +/****** Object: StoredProcedure [vesp_SessionCheckOutItem] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SessionCheckOutItem]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_SessionCheckOutItem]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[vesp_SessionCheckOutItem] +( + @SessionID int, + @ItemID int, + @ItemType int, + @OwnerID int OUTPUT +) +WITH EXECUTE AS OWNER +AS +BEGIN + INSERT INTO Owners (SessionID, OwnerItemID, OwnerType) VALUES (@SessionID, @ItemID, @ItemType) + SELECT @OwnerID = SCOPE_IDENTITY() +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SessionCheckOutItem Succeeded' +ELSE PRINT 'Procedure Creation: vesp_SessionCheckOutItem Error on Creation' +GO + +/****** Object: StoredProcedure [vesp_SessionCheckInItem] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vesp_SessionCheckInItem]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [vesp_SessionCheckInItem]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[vesp_SessionCheckInItem] +( + @OwnerID int +) +WITH EXECUTE AS OWNER +AS +BEGIN + DELETE FROM Owners WHERE OwnerID = @OwnerID +END +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SessionCheckInItem Succeeded' +ELSE PRINT 'Procedure Creation: vesp_SessionCheckInItem Error on Creation' +GO + +/****** Object: StoredProcedure [getOwnerByItemID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getOwnerByItemID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getOwnerByItemID]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getOwnerByItemID] + +( + @ItemID int, + @ItemType int +) +WITH EXECUTE AS OWNER +AS + SELECT + [OwnerID], + [SessionID], + [OwnerType], + [OwnerItemID], + [DTSStart], + [LastChanged] + FROM [Owners] + WHERE [OwnerItemID]=@ItemID AND [OwnerType]=@ItemType + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getOwnerByItemID Succeeded' +ELSE PRINT 'Procedure Creation: getOwnerByItemID Error on Creation' +GO + +/****** Object: StoredProcedure [getOwnerBySessionIDandVersionID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getOwnerBySessionIDandVersionID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getOwnerBySessionIDandVersionID]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getOwnerBySessionIDandVersionID] + +( + @SessionID int, + @VersionID int +) +WITH EXECUTE AS OWNER +AS + SELECT + [OwnerID], + [SessionID], + [OwnerType], + [OwnerItemID], + [DTSStart], + [LastChanged] + FROM [Owners] oo + INNER JOIN + ( + SELECT 0 ObjectType,ItemID ObjectID FROM dbo.vefn_GetVersionItems(@VersionID) + UNION + SELECT 1 ObjectType,ee.DocID ObjectID FROM dbo.vefn_GetVersionItems(@VersionID) vi + INNER JOIN Contents cc ON vi.ContentID = cc.ContentID + INNER JOIN Entries ee ON vi.ContentID = ee.ContentID + UNION + SELECT 2 ObjectType, @VersionID ObjectID + ) tt ON oo.OwnerType = tt.ObjectType and oo.OwnerItemID = tt.ObjectID + WHERE [SessionID] = @SessionID + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getOwnerBySessionIDandVersionID Succeeded' +ELSE PRINT 'Procedure Creation: getOwnerBySessionIDandVersionID Error on Creation' +GO + +/****** Object: StoredProcedure [getUserByUserID] ******/ +IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getUserByUserID]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) + DROP PROCEDURE [getUserByUserID]; +GO + +/***************************************************************************** + Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE + Copyright 2012 - Volian Enterprises, Inc. All rights reserved. +*****************************************************************************/ +CREATE PROCEDURE [dbo].[getUserByUserID] + +( + @UserID varchar(100) +) +WITH EXECUTE AS OWNER +AS + SELECT + [UID], + [UserID], + [FirstName], + [MiddleName], + [LastName], + [Suffix], + [CourtesyTitle], + [PhoneNumber], + [CFGName], + [UserLogin], + [UserName], + [Config], + [DTS], + [UsrID], + [LastChanged], + (SELECT COUNT(*) FROM [Memberships] WHERE [Memberships].[UID]=[Users].[UID]) [MembershipCount] + FROM [Users] + WHERE [UserID]=@UserID + + SELECT + [Memberships].[UGID], + [Memberships].[UID], + [Memberships].[GID], + [Memberships].[StartDate], + [Memberships].[EndDate], + [Memberships].[Config], + [Memberships].[DTS], + [Memberships].[UsrID], + [Memberships].[LastChanged], + [Groups].[GroupName] [Group_GroupName], + [Groups].[GroupType] [Group_GroupType], + [Groups].[Config] [Group_Config], + [Groups].[DTS] [Group_DTS], + [Groups].[UsrID] [Group_UsrID] + FROM [Memberships] + JOIN [Groups] ON + [Groups].[GID]=[Memberships].[GID] + JOIN [Users] ON [Memberships].[UID] = [Users].[UID] + WHERE + [Users].[UserID]=@UserID + + RETURN +GO +-- Display the status of Proc creation +IF (@@Error = 0) PRINT 'Procedure Creation: getUserByUserID Succeeded' +ELSE PRINT 'Procedure Creation: getUserByUserID Error on Creation' +GO + +--need to check to see if security is already defined. if not then do this stuff +declare @aCount int +select @aCount = count(*) from assignments +if @aCount = 0 +begin +--clean up security related tables + EXEC sp_executesql N' + delete from [Assignments]' + EXEC sp_executesql N' + dbcc checkident([Assignments],reseed,0)' + EXEC sp_executesql N' + delete from [Memberships]' + EXEC sp_executesql N' + dbcc checkident([Memberships],reseed,0)' + EXEC sp_executesql N' + delete from [Permissions]' + EXEC sp_executesql N' + dbcc checkident([Permissions],reseed,0)' + EXEC sp_executesql N' + delete from [Roles]' + EXEC sp_executesql N' + dbcc checkident([Roles],reseed,0)' + EXEC sp_executesql N' + delete from [Users]' + EXEC sp_executesql N' + dbcc checkident([Users],reseed,0)' + EXEC sp_executesql N' + delete from [Groups]' + EXEC sp_executesql N' + dbcc checkident([Groups],reseed,0)' + + --define Roles + EXEC sp_executesql N' + insert into Roles (Name,Title,DTS,UsrID) values + (''Administrator'',''Manage Generic Data;Manage Security;Edit RO Values,Create FST,Update RO Values;Update Formats;PROMS Settings;Create/Update/Delete Folders,DocVersions,Procedures,Sections,Steps,All Annotations'',getdate(),''VEPROMS'')' + EXEC sp_executesql N' + insert into Roles (Name,Title,DTS,UsrID) values + (''Set Administrator'',''Edit RO Values,Create FST,Update RO Values;Create/Update/Delete Folders,DocVersions,Procedures,Sections,Steps,All Set Annotations'',getdate(),''VEPROMS'')' + EXEC sp_executesql N' + insert into Roles (Name,Title,DTS,UsrID) values + (''Writer'',''Create/Update/Delete Procedures,Sections,Steps,All Set Annotations'',getdate(),''VEPROMS'')' + EXEC sp_executesql N' + insert into Roles (Name,Title,DTS,UsrID) values + (''Reviewer'',''Create/Update/Delete User Annotations'',getdate(),''VEPROMS'')' + EXEC sp_executesql N' + insert into Roles (Name,Title,DTS,UsrID) values + (''RO Editor'',''Edit RO Values,Create FST'',getdate(),''VEPROMS'')' + + --define Permissions for Roles + EXEC sp_executesql N' + declare @rid int; + select @rid = rid from roles where name = ''Administrator''; + insert into permissions (rid,permlevel,versiontype,permvalue,permad,startdate,dts,usrid) values + (@rid,1,3,15,0,getdate(),getdate(),''VEPROMS'')' + EXEC sp_executesql N' + declare @rid int; + select @rid = rid from roles where name = ''Set Administrator''; + insert into permissions (rid,permlevel,versiontype,permvalue,permad,startdate,dts,usrid) values + (@rid,2,3,15,0,getdate(),getdate(),''VEPROMS'')' + EXEC sp_executesql N' + declare @rid int; + select @rid = rid from roles where name = ''Writer''; + insert into permissions (rid,permlevel,versiontype,permvalue,permad,startdate,dts,usrid) values + (@rid,4,3,15,0,getdate(),getdate(),''VEPROMS'')' + EXEC sp_executesql N' + declare @rid int; + select @rid = rid from roles where name = ''Reviewer''; + insert into permissions (rid,permlevel,versiontype,permvalue,permad,startdate,dts,usrid) values + (@rid,7,3,15,0,getdate(),getdate(),''VEPROMS'')' + EXEC sp_executesql N' + declare @rid int; + select @rid = rid from roles where name = ''RO Editor''; + insert into permissions (rid,permlevel,versiontype,permvalue,permad,startdate,dts,usrid) values + (@rid,3,3,15,0,getdate(),getdate(),''VEPROMS'')' + + --define adminstrator Group + EXEC sp_executesql N' + insert into groups (groupname,dts,usrid) + select name + ''s'',getdate(),''VEPROMS'' from roles where name = ''Administrator''' + + --define administrator Assignment + EXEC sp_executesql N' + insert into assignments (gid,rid,folderid,startdate,dts,usrid) + select gg.gid,rr.rid,1,getdate(),getdate(),''VEPROMS'' from roles rr inner join groups gg on rr.name + ''s'' = gg.groupname' + EXEC sp_executesql N' + print ''MultiUser and Security Created''' +end +else begin + EXEC sp_executesql N' + print ''MultiUser and Security Exists''' +end +GO