From 65337fc69dc39bb169135ebaafab2f3fd9466c38 Mon Sep 17 00:00:00 2001 From: Freddy Kristiansen Date: Fri, 5 Apr 2024 13:43:47 +0200 Subject: [PATCH] Issue #3467 (#3468) 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 --- AppHandling/Clean-BcContainerDatabase.ps1 | 4 ++-- AppHandling/Compile-AppInNavContainer.ps1 | 2 +- Bacpac/Backup-NavContainerDatabases.ps1 | 2 +- Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 | 2 +- Bacpac/Restore-DatabasesInNavContainer.ps1 | 2 +- ContainerHandling/New-NavContainer.ps1 | 4 ++-- Misc/Set-BcContainerFeatureKeys.ps1 | 2 +- ReleaseNotes.txt | 4 ++++ Version.txt | 2 +- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/AppHandling/Clean-BcContainerDatabase.ps1 b/AppHandling/Clean-BcContainerDatabase.ps1 index 2211fee48..a7a593405 100644 --- a/AppHandling/Clean-BcContainerDatabase.ps1 +++ b/AppHandling/Clean-BcContainerDatabase.ps1 @@ -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 @@ -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" diff --git a/AppHandling/Compile-AppInNavContainer.ps1 b/AppHandling/Compile-AppInNavContainer.ps1 index 6153768eb..1eb0d0ad1 100644 --- a/AppHandling/Compile-AppInNavContainer.ps1 +++ b/AppHandling/Compile-AppInNavContainer.ps1 @@ -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 } diff --git a/Bacpac/Backup-NavContainerDatabases.ps1 b/Bacpac/Backup-NavContainerDatabases.ps1 index 922a83e8f..fece5b090 100644 --- a/Bacpac/Backup-NavContainerDatabases.ps1 +++ b/Bacpac/Backup-NavContainerDatabases.ps1 @@ -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 ( diff --git a/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 b/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 index 65e99c495..d71f3d9ce 100644 --- a/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 +++ b/Bacpac/Export-NavContainerDatabasesAsBacpac.ps1 @@ -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( diff --git a/Bacpac/Restore-DatabasesInNavContainer.ps1 b/Bacpac/Restore-DatabasesInNavContainer.ps1 index 5fd766087..ad384ded3 100644 --- a/Bacpac/Restore-DatabasesInNavContainer.ps1 +++ b/Bacpac/Restore-DatabasesInNavContainer.ps1 @@ -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 ( diff --git a/ContainerHandling/New-NavContainer.ps1 b/ContainerHandling/New-NavContainer.ps1 index 5ded79bb5..b26336afc 100644 --- a/ContainerHandling/New-NavContainer.ps1 +++ b/ContainerHandling/New-NavContainer.ps1 @@ -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;" @@ -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) diff --git a/Misc/Set-BcContainerFeatureKeys.ps1 b/Misc/Set-BcContainerFeatureKeys.ps1 index 6c2e27c2f..39f6d35d8 100644 --- a/Misc/Set-BcContainerFeatureKeys.ps1 +++ b/Misc/Set-BcContainerFeatureKeys.ps1 @@ -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 diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 9d7982a90..b6a9c5b11 100644 --- a/ReleaseNotes.txt +++ b/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 diff --git a/Version.txt b/Version.txt index 470629b9d..b714a809c 100644 --- a/Version.txt +++ b/Version.txt @@ -1 +1 @@ -6.0.14-dev +6.0.15-dev