From 0deea55d7edb648bed53b3d9b3db14ad1855cdf6 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 10 Feb 2017 16:22:09 +0000 Subject: [PATCH] Cleanup Sessions and Owners before beginning a session --- PROMS/DataLoader/PROMSFixes.Sql | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/PROMS/DataLoader/PROMSFixes.Sql b/PROMS/DataLoader/PROMSFixes.Sql index 7b59f8d2..1a62cad4 100644 --- a/PROMS/DataLoader/PROMSFixes.Sql +++ b/PROMS/DataLoader/PROMSFixes.Sql @@ -7507,6 +7507,17 @@ CREATE PROCEDURE [dbo].[vesp_SessionBegin] WITH EXECUTE AS OWNER AS BEGIN TRY -- Try Block + BEGIN TRANSACTION + -- Cleanup Old Records before checking for Owner Records + --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, -5, getdate())) + DELETE FROM Owners WHERE SessionID in (SELECT SessionID FROM Sessions WHERE 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, -5, getdate()) + DELETE FROM Sessions WHERE DTSEnd is null and DTSActivity < DATEADD(minute, -15, getdate()) + DELETE FROM Owners WHERE SessionID not in (SELECT SessionID FROM Sessions) DECLARE @oCount int SELECT @oCount = count(*) FROM Owners WHERE OwnerType = 4 IF @oCount > 0 BEGIN @@ -7524,16 +7535,6 @@ BEGIN TRY -- Try Block WHERE [SessionID]=0 END ELSE BEGIN - 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, -5, getdate())) - DELETE FROM Owners WHERE SessionID in (SELECT SessionID FROM Sessions WHERE 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, -5, getdate()) - DELETE FROM Sessions WHERE DTSEnd is null and DTSActivity < DATEADD(minute, -15, getdate()) - DELETE FROM Owners WHERE SessionID not in (SELECT SessionID FROM Sessions) INSERT INTO [Sessions]([UserID],[MachineName],[ProcessID]) VALUES (@UserID, @MachineName, @ProcessID) SELECT @@ -13115,7 +13116,7 @@ IF (@@Error = 0) PRINT 'StoredProcedure [vesp_CleanUpROAssociations] Succeeded' ELSE PRINT 'StoredProcedure [vesp_CleanUpROAssociations] Error on Creation' go -PRINT 'Admin Tools Additional queries for Cleanup RO Assoc and Cleanup of Unused RO Fsts and Figures.' +PRINT 'Updated vesp_SessionBegin to clear old Owner Records' ----------------------------------------------------------------------------- /* @@ -13142,8 +13143,8 @@ BEGIN TRY -- Try Block set nocount on DECLARE @RevDate varchar(255) DECLARE @RevDescription varchar(255) - set @RevDate = '10/31/2016 2:40 PM' - set @RevDescription = 'Removed Kewneee, Point Beach, and un-used Summer formats' + set @RevDate = '1/9/2017 4:45 PM' + set @RevDescription = 'Fixed vesp_SessionBegin' Select cast(@RevDate as datetime) RevDate, @RevDescription RevDescription PRINT 'SQL Code Revision ' + @RevDate + ' - ' + @RevDescription IF( @@TRANCOUNT > 0 ) COMMIT