Skip to content

Commit 1bdff1b

Browse files
committed
(#291) Improves Idempotency of SQL Setup
Previously, re-running could result in a user being in use and consequently not being dropped.
1 parent 1c32d26 commit 1bdff1b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

modules/C4B-Environment/C4B-Environment.psm1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,9 @@ function Add-DatabaseUserAndRoles {
540540
USE [master]
541541
IF EXISTS(SELECT * FROM msdb.sys.syslogins WHERE UPPER([name]) = UPPER('$Username'))
542542
BEGIN
543+
DECLARE @kill varchar(8000) = '';
544+
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';' FROM sys.dm_exec_sessions WHERE UPPER([login_name]) = UPPER('$Username')
545+
EXEC(@kill);
543546
DROP LOGIN [$Username]
544547
END
545548

0 commit comments

Comments
 (0)