mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
prevent attach failure when db name contains '.'
When a database name along the lines of "WidgetCatalog_v8.3.433" is passed into the script, attach fails at the "v8.3". Rather than deal with trying to properly escape/encode a `[` and `]` around the names, I found that escaping them with quotes behaves as expected.
This commit is contained in:
@ -46,7 +46,7 @@ if ($null -ne $dbs -And $dbs.Length -gt 0){
|
||||
}
|
||||
|
||||
$files = $files -join ","
|
||||
$sqlcmd = "sp_detach_db $($db.dbName);CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;"
|
||||
$sqlcmd = "sp_detach_db ""$($db.dbName)"";CREATE DATABASE ""$($db.dbName)"" ON $($files) FOR ATTACH ;"
|
||||
|
||||
Write-Verbose "Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance '.\SQLEXPRESS'"
|
||||
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
|
||||
@ -54,4 +54,4 @@ if ($null -ne $dbs -And $dbs.Length -gt 0){
|
||||
}
|
||||
|
||||
Write-Verbose "Started SQL Server."
|
||||
while ($true) { Start-Sleep -Seconds 3600 }
|
||||
while ($true) { Start-Sleep -Seconds 3600 }
|
||||
|
||||
Reference in New Issue
Block a user