Skip to content

Commit 08e2f35

Browse files
MattTraxingerMatt Traxinger
and
Matt Traxinger
authored
Give Option to Choose SQL PowerShell Module When Restoring From BacPac (#3763)
Fixes #3762 This is a change to how Restore-BcDatabaseFromArtifacts chooses which PowerShell module to use. I have added an optional parameter, SqlModuleToUse, with two possible values, sqlps and sqlserver, and a default value of sqlps to preserve existing functionality. I've also added the same parameter to New-BcContainer. --------- Co-authored-by: Matt Traxinger <[email protected]>
1 parent c47d8ca commit 08e2f35

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

BC.HelperFunctions.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function Get-ContainerHelperConfig {
119119
"IsAzureDevOps" = ($env:TF_BUILD -eq "true")
120120
"IsGitLab" = ($env:GITLAB_CI -eq "true")
121121
"useApproximateVersion" = $false
122+
"useSqlServerModule" = $false
122123
}
123124

124125
if ($isInsider) {

Bacpac/Restore-BcDatabaseFromArtifacts.ps1

+11-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
Include this parameter if you want to restore the database asynchronous. A file called <databasePrefix>databasescreated.txt will be created in the containerhelper folder when done
2323
.Parameter sqlTimeout
2424
SQL Timeout for database restore operations
25+
.Parameter useSqlServerModule
26+
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.
2527
#>
2628
function Restore-BcDatabaseFromArtifacts {
2729
Param(
@@ -39,7 +41,8 @@ function Restore-BcDatabaseFromArtifacts {
3941
[string] $bakFile,
4042
[switch] $multitenant,
4143
[switch] $async,
42-
[int] $sqlTimeout = -1
44+
[int] $sqlTimeout = -1,
45+
[switch] $useSqlServerModule = $bcContainerHelperConfig.useSqlServerModule
4346
)
4447

4548
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
@@ -57,7 +60,7 @@ try {
5760
$containerHelperPath = (Get-Item (Join-Path $PSScriptRoot "..\Import-BcContainerHelper.ps1")).FullName
5861
Write-Host $containerHelperPath
5962

60-
$job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout )
63+
$job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout, $useSqlServerModule )
6164
$ErrorActionPreference = "Stop"
6265
try {
6366
. "$containerHelperPath"
@@ -98,8 +101,11 @@ try {
98101
if ($multitenant) {
99102
$dbName = "$($databasePrefix)tenant"
100103
}
101-
Import-Module sqlps -ErrorAction SilentlyContinue
102-
$sqlpsModule = get-module sqlps
104+
$sqlpsModule = $null
105+
if(-not $useSqlServerModule) {
106+
Import-Module sqlps -ErrorAction SilentlyContinue
107+
$sqlpsModule = get-module sqlps
108+
}
103109
if (-not $sqlpsModule) {
104110
import-module SqlServer
105111
$SqlModule = get-module SqlServer
@@ -222,7 +228,7 @@ try {
222228
throw
223229
}
224230

225-
} -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout
231+
} -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout, $useSqlServerModule.IsPresent
226232

227233
if (!$async) {
228234
While ($job.State -eq "Running") {

ContainerHandling/New-NavContainer.ps1

+5-2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@
179179
Use Get-AlLanguageExtensionFromArtifacts -artifactUrl (Get-BCArtifactUrl -select NextMajor -accept_insiderEula) to get latest insider .vsix
180180
.Parameter sqlTimeout
181181
SQL Timeout for database restore operations
182+
.Parameter useSqlServerModule
183+
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.
182184
.Example
183185
New-BcContainer -accept_eula -containerName test
184186
.Example
@@ -287,7 +289,8 @@ function New-BcContainer {
287289
[switch] $doNotUseRuntimePackages = $true,
288290
[string] $vsixFile = "",
289291
[string] $applicationInsightsKey,
290-
[scriptblock] $finalizeDatabasesScriptBlock
292+
[scriptblock] $finalizeDatabasesScriptBlock,
293+
[switch] $useSqlServerModule = $bcContainerHelperConfig.useSqlServerModule
291294
)
292295

293296
$telemetryScope = InitTelemetryScope `
@@ -526,7 +529,7 @@ try {
526529
$multitenant = $bcContainerHelperConfig.sandboxContainersAreMultitenantByDefault
527530
}
528531
Remove-BcDatabase -databaseServer $databaseServer -databaseInstance $databaseInstance -databaseName "$($databasePrefix)%"
529-
Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl -databaseServer $databaseServer -databaseInstance $databaseInstance -databasePrefix $databasePrefix -databaseName $databaseName -multitenant:$multitenant -bakFile $bakFile -async
532+
Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl -databaseServer $databaseServer -databaseInstance $databaseInstance -databasePrefix $databasePrefix -databaseName $databaseName -multitenant:$multitenant -bakFile $bakFile -useSqlServerModule:$useSqlServerModule.IsPresent -async
530533
$createTenantAndUserInExternalDatabase = $true
531534
$bakFile = ""
532535
$successFileName = Join-Path $bcContainerHelperConfig.containerHelperFolder "$($databasePrefix)databasescreated.txt"

ReleaseNotes.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
6.0.30
2+
Issue 3762 Give Option to Choose SQL PowerShell Module When Restoring From BacPac
3+
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.
4+
15
6.0.29
26
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.
37
Improve performance and reduce memory consumption when creating and pushing NuGet packages

0 commit comments

Comments
 (0)