Closed michvllni closed 2 years ago
You should set an environment variable databaseInstance to an empty string. On the .ndf - I assume that the SQL image is generating this - isn't there a way to just use ldf and mdf ?
Setting the databaseInstance to an empty string resolved the issue with the instance.
Unfortunately all our databases are structured like that (I don't know why). Meaning all databases we use consist of an mdf, an ndf and a ldf file
I've been using something similar as you use it here when restoring the backup in the sql container...maybe it could help you resolve the issue?
$sqlversion = 15
$bakPathCleaned = $env:bakPath.TrimStart('\\').TrimEnd('\\')
if (Test-Path "$bakPathCleaned") {
Write-Host "Restoring $bakPathCleaned"
$sqlcmd = "RESTORE FILELISTONLY FROM DISK = '$bakPathCleaned'"
$files = sqlcmd -Q $sqlcmd -s "," -W
$files = $files[2..($files.length - 3)] #remove header and footer
$importcmd = "RESTORE DATABASE mydatabase FROM DISK = '$bakPathCleaned'"
if ($files.Count -gt 0) {
$importcmd += "WITH "
foreach ($file in $files) {
$fileRow = $file -split ","
$logicalName = $fileRow[0]
$physicalName = Join-Path "C:\Program Files\Microsoft SQL Server\MSSQL$sqlVersion.MSSQLSERVER\MSSQL\DATA" (Split-Path $fileRow[1] -Leaf)
if ($importcmd -like "*MOVE*TO*") {
$importcmd += ","
}
$importcmd += "MOVE '$logicalName' TO '$physicalName'"
}
}
sqlcmd -Q "$importcmd"
if (!$?) {
exit 1
}
}
else {
Write-Host "Could not find $bakPathCleaned"
Exit 1
}
Edit: Using Invoke-SQLCmd would make things a lot easier, but I'm not in the mood of touching the images at the moment
The Export function was created to allow container databases to be exported as bacpac and container databases do not have this problem and I haven't heard this problem from other partners.
it isn't something I will have the time to look at before my summer vacation - meaning that at the earliest, it will be august or september.
Feel free to submit a PR on this https://github.com/microsoft/navcontainerhelper/blob/master/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 if you cannot wait
Maybe the .ndf file can just be ignored
Thank you for the hint. It appears it is not an issue with the export function but rather with the copy-navdatabase function in nav-docker. I will take a closer look at it tomorrow and send a pull request your way if that's okay for you
nav-docker is the generic image. To test, you can place a new helperfunctions in the c:\run\my folder of the container when you create the container. Then that will override the existing.
Fixing the helper function in nav-docker did the trick for me. I've created a PR there.
PLEASE DO NOT INCLUDE ANY PASSWORDS OR TOKENS IN YOUR ISSUE!!!
Describe the issue When trying to export a bacpac from a database using
Export-BcContainerDatabasesAsBacpac
on a database that has an .ndf file it fails to correctly restore the database as temp database after backing it up.Please not that my SQL server lies in a separate container that is connected to the BC container via docker compose:
Scripts used to create container and cause the issue
Output:
Everything starts up fine, but when executing
Export-BcContainerDatabasesAsBacpac -containerName seminar-master -sqlCredential $cred -bacpacFolder 'C:\data\' -diagnostics
I get the following output ($cred contains the login credentials for the sql server as defined in the compose): Full output of scripts
It appears that the ndf file fails to get a file path to which it can be restored and thus the SQL command is incomplete (line 6). Additionally, the script appears to add an instance
SQLEXPRESS
because the sql container does not use an instance (line 3).The files in the database look like this: