Skip to content

Commit 253dd2b

Browse files
Add alter DB query before dropping database
Co-authored-by: michalsn <michal@sniatala.pl>
1 parent f4dba7b commit 253dd2b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

system/Database/SQLSRV/Forge.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,25 @@ public function createDatabase(string $dbName, bool $ifNotExists = false): bool
168168
}
169169
}
170170

171+
/**
172+
* {@inheritDoc}
173+
*
174+
* @see https://stackoverflow.com/questions/7469130/cannot-drop-database-because-it-is-currently-in-use
175+
*/
176+
public function dropDatabase(string $dbName): bool
177+
{
178+
try {
179+
$this->db->query(sprintf(
180+
'ALTER DATABASE %s SET SINGLE_USER WITH ROLLBACK IMMEDIATE',
181+
$this->db->escapeIdentifier($dbName),
182+
));
183+
} catch (DatabaseException) {
184+
// no-op
185+
}
186+
187+
return parent::dropDatabase($dbName);
188+
}
189+
171190
/**
172191
* CREATE TABLE attributes
173192
*/

0 commit comments

Comments
 (0)