diff --git a/BC.HelperFunctions.ps1 b/BC.HelperFunctions.ps1 index 3c879064e..419be0697 100644 --- a/BC.HelperFunctions.ps1 +++ b/BC.HelperFunctions.ps1 @@ -119,6 +119,7 @@ function Get-ContainerHelperConfig { "IsAzureDevOps" = ($env:TF_BUILD -eq "true") "IsGitLab" = ($env:GITLAB_CI -eq "true") "useApproximateVersion" = $false + "useSqlServerModule" = $false } if ($isInsider) { diff --git a/Bacpac/Restore-BcDatabaseFromArtifacts.ps1 b/Bacpac/Restore-BcDatabaseFromArtifacts.ps1 index d6c98af98..3f271c699 100644 --- a/Bacpac/Restore-BcDatabaseFromArtifacts.ps1 +++ b/Bacpac/Restore-BcDatabaseFromArtifacts.ps1 @@ -22,6 +22,8 @@ Include this parameter if you want to restore the database asynchronous. A file called databasescreated.txt will be created in the containerhelper folder when done .Parameter sqlTimeout SQL Timeout for database restore operations + .Parameter useSqlServerModule + Switch, forces the use of the sqlserver module instead of the sqlps module. Default is to use the sqlps module. The default can be changed in the bcContainerHelperConfig file by setting "useSqlServerModule" = $false. #> function Restore-BcDatabaseFromArtifacts { Param( @@ -39,7 +41,8 @@ function Restore-BcDatabaseFromArtifacts { [string] $bakFile, [switch] $multitenant, [switch] $async, - [int] $sqlTimeout = -1 + [int] $sqlTimeout = -1, + [switch] $useSqlServerModule = $bcContainerHelperConfig.useSqlServerModule ) $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @() @@ -57,7 +60,7 @@ try { $containerHelperPath = (Get-Item (Join-Path $PSScriptRoot "..\Import-BcContainerHelper.ps1")).FullName Write-Host $containerHelperPath - $job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout ) + $job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout, $useSqlServerModule ) $ErrorActionPreference = "Stop" try { . "$containerHelperPath" @@ -98,8 +101,11 @@ try { if ($multitenant) { $dbName = "$($databasePrefix)tenant" } - Import-Module sqlps -ErrorAction SilentlyContinue - $sqlpsModule = get-module sqlps + $sqlpsModule = $null + if(-not $useSqlServerModule) { + Import-Module sqlps -ErrorAction SilentlyContinue + $sqlpsModule = get-module sqlps + } if (-not $sqlpsModule) { import-module SqlServer $SqlModule = get-module SqlServer @@ -222,7 +228,7 @@ try { throw } - } -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout + } -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout, $useSqlServerModule.IsPresent if (!$async) { While ($job.State -eq "Running") { diff --git a/ContainerHandling/New-NavContainer.ps1 b/ContainerHandling/New-NavContainer.ps1 index bde4c622c..085cd42a4 100644 --- a/ContainerHandling/New-NavContainer.ps1 +++ b/ContainerHandling/New-NavContainer.ps1 @@ -179,6 +179,8 @@ Use Get-AlLanguageExtensionFromArtifacts -artifactUrl (Get-BCArtifactUrl -select NextMajor -accept_insiderEula) to get latest insider .vsix .Parameter sqlTimeout SQL Timeout for database restore operations + .Parameter useSqlServerModule + Switch, forces the use of the sqlserver module instead of the sqlps module. Default is to use the sqlps module. The default can be changed in the bcContainerHelperConfig file by setting "useSqlServerModule" = $false. .Example New-BcContainer -accept_eula -containerName test .Example @@ -287,7 +289,8 @@ function New-BcContainer { [switch] $doNotUseRuntimePackages = $true, [string] $vsixFile = "", [string] $applicationInsightsKey, - [scriptblock] $finalizeDatabasesScriptBlock + [scriptblock] $finalizeDatabasesScriptBlock, + [switch] $useSqlServerModule = $bcContainerHelperConfig.useSqlServerModule ) $telemetryScope = InitTelemetryScope ` @@ -526,7 +529,7 @@ try { $multitenant = $bcContainerHelperConfig.sandboxContainersAreMultitenantByDefault } Remove-BcDatabase -databaseServer $databaseServer -databaseInstance $databaseInstance -databaseName "$($databasePrefix)%" - Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl -databaseServer $databaseServer -databaseInstance $databaseInstance -databasePrefix $databasePrefix -databaseName $databaseName -multitenant:$multitenant -bakFile $bakFile -async + Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl -databaseServer $databaseServer -databaseInstance $databaseInstance -databasePrefix $databasePrefix -databaseName $databaseName -multitenant:$multitenant -bakFile $bakFile -useSqlServerModule:$useSqlServerModule.IsPresent -async $createTenantAndUserInExternalDatabase = $true $bakFile = "" $successFileName = Join-Path $bcContainerHelperConfig.containerHelperFolder "$($databasePrefix)databasescreated.txt" diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 5d6158178..8e0e7bd57 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,3 +1,7 @@ +6.0.30 +Issue 3762 Give Option to Choose SQL PowerShell Module When Restoring From BacPac +There are instances where sqlps does not work as expected when it is installed. This change adds a switch parameter, useSqlServerModule, to Restore-BcDatabaseFromArtifacts, New-NavContainer, and the BcContainerHelper config file. + 6.0.29 Issue 3591 When using Publish-NAVApp to publish an app, which fails compilation in the service, the command might hang forever - the fix for this is a temporary hack put in place for the versions which doesn't work. Improve performance and reduce memory consumption when creating and pushing NuGet packages