Skip to content

Commit

Permalink
add trustServerCertificate if the parameter exists (#3579)
Browse files Browse the repository at this point in the history
Fixes #3572

---------

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk committed Jul 6, 2024
1 parent b241069 commit 0618f7a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Api/Invoke-NavContainerApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
.Parameter silent
Include the silent switch to avoid the printout of the URL invoked
.Example
$result = Invoke-BcContainerApi -containerName $containerName -tenant $tenant -APIVersion "beta" -Query "companies?`$filter=$companyFilter" -credential $credential
$result = Invoke-BcContainerApi -containerName $containerName -tenant $tenant -APIVersion "v2.0" -Query "companies?`$filter=$companyFilter" -credential $credential
.Example
Invoke-BcContainerApi -containerName $containerName -CompanyId $companyId -APIVersion "beta" -Query "customers" -credential $credential | Select-Object -ExpandProperty value
Invoke-BcContainerApi -containerName $containerName -CompanyId $companyId -APIVersion "v2.0" -Query "customers" -credential $credential | Select-Object -ExpandProperty value
.Example
Invoke-BcContainerApi -containerName $containerName -CompanyId $companyId -APIVersion "beta" -Query "customers?`$filter=$([Uri]::EscapeDataString("number eq '10000'"))" -credential $credential | Select-Object -ExpandProperty value
Invoke-BcContainerApi -containerName $containerName -CompanyId $companyId -APIVersion "v2.0" -Query "customers?`$filter=$([Uri]::EscapeDataString("number eq '10000'"))" -credential $credential | Select-Object -ExpandProperty value
.Example
Invoke-BcContainerApi -containerName $containerName -CompanyId $companyId -APIVersion "beta" -Query "salesInvoices?`$filter=$([Uri]::EscapeDataString("status eq 'Open' and totalAmountExcludingTax gt 1000.00"))" -credential $credential | Select-Object -ExpandProperty value
Invoke-BcContainerApi -containerName $containerName -CompanyId $companyId -APIVersion "v2.0" -Query "salesInvoices?`$filter=$([Uri]::EscapeDataString("status eq 'Open' and totalAmountExcludingTax gt 1000.00"))" -credential $credential | Select-Object -ExpandProperty value
#>
function Invoke-BcContainerApi {
Param (
Expand Down
23 changes: 15 additions & 8 deletions Bacpac/Remove-BcDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,31 @@ try {
$op = "="
}

$dbFiles = Invoke-SqlCmd `
-ServerInstance $databaseserverinstance `
$sqlParams = @{
"ServerInstance" = $databaseserverinstance
}
$function = Get-Command 'Invoke-SqlCmd' -ErrorAction SilentlyContinue
if ($null -eq $function) {
throw "Invoke-SqlCmd not found, please install the SqlServer module"
}
if ($function.Parameters.ContainsKey('TrustServerCertificate')) {
$sqlParams += @{ "TrustServerCertificate" = $true }
}

$dbFiles = Invoke-SqlCmd @sqlParams `
-Query "SELECT f.physical_name FROM sys.sysdatabases db INNER JOIN sys.master_files f ON f.database_id = db.dbid WHERE db.name $op '$DatabaseName'" | ForEach-Object { $_.physical_name }

$databases = Invoke-SqlCmd `
-ServerInstance $databaseserverinstance `
$databases = Invoke-SqlCmd @sqlParams `
-Query "SELECT * FROM sys.sysdatabases WHERE name $op '$DatabaseName'" | ForEach-Object { $_.name }

$databases | ForEach-Object {

Write-Host "Setting database $_ offline"
Invoke-SqlCmd `
-ServerInstance $DatabaseServerInstance `
Invoke-SqlCmd @sqlParams `
-Query "ALTER DATABASE [$_] SET OFFLINE WITH ROLLBACK IMMEDIATE"

Write-Host "Removing database $_"
Invoke-SqlCmd `
-ServerInstance $DatabaseServerInstance `
Invoke-SqlCmd @sqlParams `
-Query "DROP DATABASE [$_]"
}

Expand Down
18 changes: 13 additions & 5 deletions Bacpac/Restore-BcDatabaseFromArtifacts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,23 @@ try {
throw "You need to have a local installation of SQL or you need the SqlServer PowerShell module installed"
}
}

$DefaultDataPath = (Invoke-SqlCmd `
-ServerInstance $databaseServerInstance `
$sqlParams = @{
"ServerInstance" = $databaseserverinstance
}
$function = Get-Command 'Invoke-SqlCmd' -ErrorAction SilentlyContinue
if ($null -eq $function) {
throw "Invoke-SqlCmd not found, please install the SqlServer module"
}
if ($function.Parameters.ContainsKey('TrustServerCertificate')) {
$sqlParams += @{ "TrustServerCertificate" = $true }
}

$DefaultDataPath = (Invoke-SqlCmd @sqlParams `
-Query "SELECT SERVERPROPERTY('InstanceDefaultDataPath') AS InstanceDefaultDataPath" ).InstanceDefaultDataPath

if($databaseServer -ne 'localhost'){
# Copy local database to SQL Server
$defaultBackupPath = (Invoke-SqlCmd `
-ServerInstance $databaseServerInstance `
$defaultBackupPath = (Invoke-SqlCmd @sqlParams `
-Query "SELECT SERVERPROPERTY('InstanceDefaultBackupPath') AS InstanceDefaultBackupPath" ).InstanceDefaultBackupPath

$qualifier = $defaultBackupPath | Split-Path -Qualifier
Expand Down
2 changes: 2 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
6.0.20

6.0.19
Issue #3560 Backup-BcContainerDatabases fails - password must be marked as read only bug
Issue #3559 ALCops can't find "Business Foundation" app and doesn't start because of it
Expand Down
2 changes: 1 addition & 1 deletion Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.19-dev
6.0.20-dev

0 comments on commit 0618f7a

Please sign in to comment.