Skip to content

Commit

Permalink
Issue #3467 (#3468)
Browse files Browse the repository at this point in the history
Fixes #3467

Issue 3467 Can't create a backup of a container with the
Backup-BCContainerDatabases commandlet
Use PowerShell 5 in places where invoke-sqlcmd or other functions from
the SqlServer PowerShell module are used

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk committed Apr 5, 2024
1 parent dd0cf4c commit 65337fc
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions AppHandling/Clean-BcContainerDatabase.ps1
Expand Up @@ -96,7 +96,7 @@ try {
$copyTables += @("Entitlement", "Entitlement Set", "Membership Entitlement")
}

Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($platformVersion, $databaseName, $databaseServer, $databaseInstance, $copyTables, $multitenant)
Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($platformVersion, $databaseName, $databaseServer, $databaseInstance, $copyTables, $multitenant)

Write-Host "Stopping ServiceTier in order to replace database"
Set-NavServerInstance -ServerInstance $ServerInstance -stop
Expand Down Expand Up @@ -196,7 +196,7 @@ try {
if ($customconfig.Multitenant -eq "True") {

Write-Host "Switching to multitenancy"
Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($databaseName, $databaseServer, $databaseInstance)
Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($databaseName, $databaseServer, $databaseInstance)
$databaseServerInstance = $databaseServer
if ($databaseInstance) {
$databaseServerInstance += "\$databaseInstance"
Expand Down
2 changes: 1 addition & 1 deletion AppHandling/Compile-AppInNavContainer.ps1
Expand Up @@ -363,7 +363,7 @@ try {
# locate application version number in database if using SQLEXPRESS
try {
if (($customConfig.DatabaseServer -eq "localhost") -and ($customConfig.DatabaseInstance -eq "SQLEXPRESS")) {
$appVersion = Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($databaseName)
$appVersion = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($databaseName)
(invoke-sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -ErrorAction Stop -Query "SELECT [applicationversion] FROM [$databaseName].[dbo].[`$ndo`$dbproperty]").applicationVersion
} -argumentList $customConfig.DatabaseName
$publishedApps += @{ "Name" = "Application"; "Publisher" = "Microsoft"; "Version" = $appversion }
Expand Down
2 changes: 1 addition & 1 deletion Bacpac/Backup-NavContainerDatabases.ps1
Expand Up @@ -49,7 +49,7 @@ try {
}
$containerBakFolder = Get-BcContainerPath -containerName $containerName -path $bakFolder -throw

Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param($containerBakfolder, $bakFolder, $tenant, $databasecredential, $compress)
Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param($containerBakfolder, $bakFolder, $tenant, $databasecredential, $compress)

function Backup {
Param (
Expand Down
2 changes: 1 addition & 1 deletion Bacpac/Export-NavContainerDatabasesAsBacpac.ps1
Expand Up @@ -64,7 +64,7 @@ try {
}
$containerBacpacFolder = Get-BcContainerPath -containerName $containerName -path $bacpacFolder -throw

Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param([PSCredential]$sqlCredential, $bacpacFolder, $tenant, $commandTimeout, $includeDacPac, $diagnostics, $additionalArguments, $doNotCheckEntitlements)
Invoke-ScriptInBcContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param([PSCredential]$sqlCredential, $bacpacFolder, $tenant, $commandTimeout, $includeDacPac, $diagnostics, $additionalArguments, $doNotCheckEntitlements)

function CmdDo {
Param(
Expand Down
2 changes: 1 addition & 1 deletion Bacpac/Restore-DatabasesInNavContainer.ps1
Expand Up @@ -70,7 +70,7 @@ try {
$containerBakFolder = Get-BcContainerPath -containerName $containerName -path $bakFolder -throw
}

Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($bakFolder, $bakFile, $databaseName, $tenant, $databaseFolder, $sqlTimeout)
Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($bakFolder, $bakFile, $databaseName, $tenant, $databaseFolder, $sqlTimeout)

function Restore {
Param (
Expand Down
4 changes: 2 additions & 2 deletions ContainerHandling/New-NavContainer.ps1
Expand Up @@ -1978,7 +1978,7 @@ if (-not `$restartingInstance) {

if ($SqlServerMemoryLimit -and $customConfig.databaseServer -eq "localhost" -and $customConfig.databaseInstance -eq "SQLEXPRESS") {
Write-Host "Set SQL Server memory limit to $SqlServerMemoryLimit MB"
Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($SqlServerMemoryLimit)
Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock { Param($SqlServerMemoryLimit)
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE;"
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'max server memory', $SqlServerMemoryLimit RECONFIGURE WITH OVERRIDE;"
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 0 RECONFIGURE WITH OVERRIDE;"
Expand Down Expand Up @@ -2376,7 +2376,7 @@ if (-not `$restartingInstance) {
if ($multitenant) {
Write-Host "Switching to multitenant"

Invoke-ScriptInBCContainer -containerName $containerName -scriptblock {
Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -scriptblock {

$customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config"
[xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile)
Expand Down
2 changes: 1 addition & 1 deletion Misc/Set-BcContainerFeatureKeys.ps1
Expand Up @@ -26,7 +26,7 @@ $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -paramet
try {

if ($featureKeys.Keys.Count -ne 0) {
Invoke-ScriptInBCContainer -containerName $containerName -ScriptBlock { Param([string] $tenant, [hashtable] $featureKeys)
Invoke-ScriptInBCContainer -containerName $containerName -usePwsh:$false -ScriptBlock { Param([string] $tenant, [hashtable] $featureKeys)
$customConfigFile = Join-Path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service").FullName "CustomSettings.config"
[xml]$customConfig = [System.IO.File]::ReadAllText($customConfigFile)
$databaseServer = $customConfig.SelectSingleNode("//appSettings/add[@key='DatabaseServer']").Value
Expand Down
4 changes: 4 additions & 0 deletions ReleaseNotes.txt
@@ -1,3 +1,7 @@
6.0.15
Issue 3467 Can't create a backup of a container with the Backup-BCContainerDatabases commandlet
Use PowerShell 5 in places where invoke-sqlcmd or other functions from the SqlServer PowerShell module are used

6.0.14
Issue 3465 Regression: Flush-ContainerHelperCache calculates wrong CacheFolder

Expand Down
2 changes: 1 addition & 1 deletion Version.txt
@@ -1 +1 @@
6.0.14-dev
6.0.15-dev

0 comments on commit 65337fc

Please sign in to comment.