Answer the question
In order to leave comments, you need to log in
How to restore a busy database from Powershell?
I want to restore the database from a backup, everything works if no one is connected to it. If there are connections to it, then it says: "Exclusive access could not be obtained because the database is in use." How to cut off connections from powershell?
Restore-SqlDatabase -ServerInstance 'srv-sql7' -Database 'Billing' -ReplaceDatabase -BackupFile $billingBackup.FullName;
Answer the question
In order to leave comments, you need to log in
$ServerName = 'srv-sql7'
$DBName = 'Billing'
$Server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $ServerName
$Server.KillAllProcesses($DBName)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question