File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -160,6 +160,27 @@ function Suspend-SqlDscDatabase
160160 if ($Force.IsPresent )
161161 {
162162 Write-Debug - Message ($script :localizedData.Database_TakingOfflineWithForce -f $sqlDatabaseObject.Name )
163+
164+ # Kill all processes before taking the database offline
165+ Write-Debug - Message ($script :localizedData.Database_KillingProcesses -f $sqlDatabaseObject.Name )
166+
167+ try
168+ {
169+ $sqlDatabaseObject.Parent.KillAllProcesses ($sqlDatabaseObject.Name )
170+ }
171+ catch
172+ {
173+ $errorMessage = $script :localizedData.Database_KillProcessesFailed -f $sqlDatabaseObject.Name
174+
175+ $PSCmdlet.ThrowTerminatingError (
176+ [System.Management.Automation.ErrorRecord ]::new(
177+ [System.InvalidOperationException ]::new($errorMessage , $_.Exception ),
178+ ' SSDD0002' , # cspell: disable-line
179+ [System.Management.Automation.ErrorCategory ]::InvalidOperation,
180+ $sqlDatabaseObject
181+ )
182+ )
183+ }
163184 }
164185 else
165186 {
@@ -168,7 +189,7 @@ function Suspend-SqlDscDatabase
168189
169190 try
170191 {
171- $sqlDatabaseObject.SetOffline ($Force .IsPresent )
192+ $sqlDatabaseObject.SetOffline ()
172193 }
173194 catch
174195 {
Original file line number Diff line number Diff line change @@ -384,8 +384,10 @@ ConvertFrom-StringData @'
384384 Database_AlreadyOffline = Database '{0}' is already offline.
385385 Database_TakingOffline = Taking database '{0}' offline.
386386 Database_TakingOfflineWithForce = Taking database '{0}' offline with force (disconnecting active users).
387+ Database_KillingProcesses = Killing all processes for database '{0}'.
387388 Database_TakenOffline = Database '{0}' was taken offline successfully.
388389 Database_SuspendFailed = Failed to take database '{0}' offline.
390+ Database_KillProcessesFailed = Failed to kill processes for database '{0}'.
389391
390392 ## New-SqlDscDatabaseSnapshot
391393 DatabaseSnapshot_Create = Creating database snapshot '{0}' from source database '{1}' on instance '{2}'. (NSDS0002)
You can’t perform that action at this time.
0 commit comments