Skip to content

Commit cc2402f

Browse files
authored
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.
1 parent 1525741 commit cc2402f

File tree

1 file changed

+2
-2
lines changed
  • samples/manage/windows-containers/mssql-server-2016-express-sp1-windows

1 file changed

+2
-2
lines changed

samples/manage/windows-containers/mssql-server-2016-express-sp1-windows/start.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ if ($null -ne $dbs -And $dbs.Length -gt 0){
4646
}
4747

4848
$files = $files -join ","
49-
$sqlcmd = "sp_detach_db $($db.dbName);CREATE DATABASE $($db.dbName) ON $($files) FOR ATTACH ;"
49+
$sqlcmd = "sp_detach_db ""$($db.dbName)"";CREATE DATABASE ""$($db.dbName)"" ON $($files) FOR ATTACH ;"
5050

5151
Write-Verbose "Invoke-Sqlcmd -Query $($sqlcmd) -ServerInstance '.\SQLEXPRESS'"
5252
Invoke-Sqlcmd -Query $sqlcmd -ServerInstance ".\SQLEXPRESS"
5353
}
5454
}
5555

5656
Write-Verbose "Started SQL Server."
57-
while ($true) { Start-Sleep -Seconds 3600 }
57+
while ($true) { Start-Sleep -Seconds 3600 }

0 commit comments

Comments
 (0)