microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
383 stars 246 forks source link

Cannot use v20 database.bak to create v21 container #2754

Closed catadumitru closed 1 year ago

catadumitru commented 1 year ago

Describe the issue I used to upgrade containers by using a backup of the old version when creating a new container. I would then upgrade the application.

When trying to create a v21 container with a v20 database.bak the server instance does not start. The error log gives the following:

An error occurred while applying changes from the object of type 'PageExtension' with ID '8700' in the 'Base Application by Microsoft 20.2.41144.41423' app to the application object of type 'Page' with the ID '8700'. Failing delta: Type: 'ObjectChangeDelta'; TargetKind: 'Other'; The error was: InvalidOperationException 
...
Server instance: BC
Category: Metadata
ClientSessionId: 00000000-0000-0000-0000-000000000000
ClientActivityId: 00000000-0000-0000-0000-000000000000
ServerSessionUniqueId: 00000000-0000-0000-0000-000000000000
ServerActivityId: a6db640b-5a40-45b6-8fd8-9aeee46b36d8
EventTime: 10/26/2022 16:23:20
Message (NavAppObjectMetadataException): ParentException: NavAppObjectMetadataException
An error occurred while applying changes from the object of type 'PageExtension' with ID '8700' in the 'Base Application by Microsoft 20.2.41144.41423' app to the application object of type 'Page' with the ID '8700'. Failing delta: Type: 'ObjectChangeDelta'; TargetKind: 'Other'; The error was: InvalidOperationException - <redacted>
ExceptionStackTrace:
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.RuntimeDeltaApplicationAdapter.HandleException(Exception ex, ApplicationObjectId objectId, DeltaAdapterContext deltaAdapterContext)
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.DeltaApplicationAdapterBase`2.PerformDeltaApplicationWithErrorHandling(ApplicationObjectId objectId, TDelta deltas, Action applicationAction)
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.DeltaApplicationAdapterBase`2.ApplyDeltas(ApplicationObjectId objectId, Object subject, IEnumerable`1 deltas, DeltaRuleEnforcer ruleEnforcer)
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.MetadataRuntimeDeltaApplicator.ApplyDeltas(DeltaApplicationContext applicationContext, Action`1 onValidDelta, Action`1 onInvalidDelta, IDeltaValidationFilter[] filters)
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.MetadataRuntimeDeltaApplicator.ApplyDeltas(DeltaApplicationContext applicationContext)
   at Microsoft.Dynamics.Nav.Runtime.NCLApplicationObjectExtension`1.ApplyRuntimeDeltas(ApplicationObjectId subjectId, TSubject subject)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaApplicationObject.ApplyExtensionObjects[T](IEnumerable`1 extensions, T subject)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetaForm.LoadPageMetadata()
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroupNewObject(NavAppGroup appGroup, NavAppGroupObjectMetadataSummary newObjectSummary, NavAppGroupInitializationType initializationType, ISet`1 targetTypesThatHaveExtensionObjects, Boolean validateMetadata)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeNewAppObjectsExcept(NavAppGroup appGroup, InitializeAppGroupProfilerSession profilerSession, NavAppGroupInitializationType initializationType, ISet`1 delayedInitializationObjectTypes, ISet`1 targetTypesThatHaveExtensionObjects, Boolean validateMetadata)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroupObjects(NavAppGroup appGroup, IReadOnlyList`1 extensionSummariesWeCareAbout, NavAppGroupInitializationType initializationType, Boolean validateMetadata)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroup(NavAppGroup appGroup, Boolean initializeOwnedObjectsOnly, Boolean validateMetadata)
InnerException:
RootException: InvalidOperationException
Metadata delta application failed due to the following error(s): Modifications to property PromotedActionCategoriesML are not supported.
ExceptionStackTrace:
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.RuntimeDeltaApplicationAdapter.ApplyDeltas(ApplicationObjectId objectId, Object subject, DeltaAdapterContext deltaAdapterContext, DeltaRuleEnforcer ruleEnforcer)
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.DeltaApplicationAdapterBase`2.<>c__DisplayClass0_1.<ApplyDeltas>b__0()
   at Microsoft.Dynamics.Nav.Apps.MetadataDeltas.DeltaApplicationAdapterBase`2.PerformDeltaApplicationWithErrorHandling(ApplicationObjectId objectId, TDelta deltas, Action applicationAction)
CallerStackTrace:
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroup(NavAppGroup appGroup, Boolean initializeOwnedObjectsOnly, Boolean validateMetadata)
   at Microsoft.Dynamics.Nav.Runtime.NCLMetadata.InitializeAppGroup(NavAppGroup appGroup, Boolean initializeOwnedObjectsOnly, Boolean validateMetadata)
   at Microsoft.Dynamics.Nav.Runtime.Apps.NavAppGroupUpdater.UpdateGroupForChangedTenant(NavTenant tenant, Boolean validateMetadata)
   at Microsoft.Dynamics.Nav.Runtime.NavTenantCollection.InitializeAppsForTenant(NavTenant tenant)
   at Microsoft.Dynamics.Nav.Runtime.NavTenantCollection.InitializeTenant(NavTenant tenant, NavTenantSettings tenantSettings, Boolean overwriteTenantIdInDatabase, Boolean verifyDatabaseConnection, Boolean ensureDatabaseExclusiveState)
   at Microsoft.Dynamics.Nav.Runtime.NavTenantCollection.AddTenant(NavTenantMountingParameters mountingParameters)
   at Microsoft.Dynamics.Nav.Runtime.NavTenantCollection.AddSingleLegacyTenant(String databaseServerName, String databaseName, String databaseUserName, ProtectedDatabasePassword databasePassword, EncryptionProvider encryptionProvider, AzureKeyVaultSettings azureKeyVaultSettings, NavDatabaseConnectionCredentialType databaseConnectionCredentialType)
   at Microsoft.Dynamics.Nav.Runtime.NavTenantCollection.ConfigureTenants(ServerUserSettings settings, String encryptionKey, Boolean isInPlacePublishing)
   at Microsoft.Dynamics.Nav.WindowsServices.NavServerWindowsService.Start(String commandLineServiceInstanceName)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Scripts used to create container and cause the issue

  $parameters += @{
        "Accept_Eula"     = $true
        "Accept_Outdated" = $true
        "Shortcuts"       = "none"
    }

 $artifactUrl = "https://bcartifacts.azureedge.net/onprem/20.2.41144.41423/w1"
 $containerName = "t202"
 New-BCContainer @Parameters `
            -doNotCheckHealth `
            -updateHosts `
            -containerName $containerName `
            -artifactUrl $artifactUrl `
            -alwaysPull:$alwaysPull `
            -auth "UserPassword" `
            -usebestcontaineros `
            -enableTaskScheduler $true `
            -Credential $credential `
            -useTraefik `
            -additionalParameters $additionalParameters `
            -PublicDnsName $publicdnsname

        $parameters += @{
            "bakFile" = "C:\ProgramData\BcContainerHelper\Extensions\t202\database.bak"
    }
Backup-BcContainerDatabases $containerName

 $artifactUrl = "https://bcartifacts.azureedge.net/onprem/21.0.46256.46853/w1"
 $containerName = "t210"
 New-BCContainer @Parameters `
            -doNotCheckHealth `
            -updateHosts `
            -containerName $containerName `
            -artifactUrl $artifactUrl `
            -alwaysPull:$alwaysPull `
            -auth "UserPassword" `
            -usebestcontaineros `
            -enableTaskScheduler $true `
            -Credential $credential `
            -useTraefik `
            -additionalParameters $additionalParameters `
            -PublicDnsName $publicdnsname

Full output of scripts

BcContainerHelper version 4.0.5
BcContainerHelper emits usage statistics telemetry to Microsoft
BcContainerHelper is version 4.0.5
BcContainerHelper is running as administrator
Hyper-V is Disabled
UsePsSession is True
Host is Microsoft Windows Server 2019 Datacenter - ltsc2019
Docker Client Version is 20.10.17
Docker Server Version is 20.10.17
Removing Session t202
Removing container t202
Removing entries from hosts
Removing t202 from container hosts file
Removing t202-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\t202
Fetching all docker images
Fetching all docker volumes
ArtifactUrl and ImageName specified
Image true:onprem-20.2.41144.41423-w1 already exists
Enabling SSL as otherwise all clients will see mixed HTTP / HTTPS request, which will cause problems e.g. on the mobile and modern windows clients
Using image true:onprem-20.2.41144.41423-w1
PublicDnsName is mywebsite.com
Disabling Health Check (always report healthy)
Creating Container t202
Style: onprem
Multitenant: No
Version: 20.2.41144.41423
Platform: 20.0.41086.41354
Generic Tag: 1.0.2.13
Container OS Version: 10.0.17763.3532 (ltsc2019)
Host OS Version: 10.0.17763.3532 (ltsc2019)
Using process isolation
Using locale en-US
Adding special CheckHealth.ps1 to enable Traefik support
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file https://myazureblob.core.windows.net/license.flf
Downloading C:\ProgramData\BcContainerHelper\Extensions\t202\my\license.flf
Additional Parameters:
-e webserverinstance=t202
-e publicdnsname=mywebsite.com
-l "traefik.protocol=https"
-l "traefik.web.frontend.rule=PathPrefix:/t202"
-l "traefik.web.port=443"
-l "traefik.soap.frontend.rule=PathPrefix:/t202soap;ReplacePathRegex: ^/t202soap(.*) /BC$1"
-l "traefik.soap.port=7047"
-l "traefik.rest.frontend.rule=PathPrefix:/t202rest;ReplacePathRegex: ^/t202rest(.*) /BC$1"
-l "traefik.rest.port=7048"
-l "traefik.dev.frontend.rule=PathPrefix:/t202dev;ReplacePathRegex: ^/t202dev(.*) /BC$1"
-l "traefik.dev.port=7049"
-l "traefik.snap.frontend.rule=PathPrefix:/t202snap;ReplacePathRegex: ^/t202snap(.*) /BC$1"
-l "traefik.snap.port=7083"
-l "traefik.dl.frontend.rule=PathPrefixStrip:/t202dl"
-l "traefik.dl.port=8080"
-l "traefik.dl.protocol=http"
-l "traefik.enable=true"
-l "traefik.frontend.entryPoints=https"
--env customNavSettings=EnableTaskScheduler=True,PublicODataBaseUrl=https://mywebsite.com/t202rest/odata,PublicSOAPBaseUrl=https://mywebsite.com/t202soap/ws,PublicWebBaseUrl=https://mywebsite.com/t202
Files in C:\ProgramData\BcContainerHelper\Extensions\t202\my:
- AdditionalOutput.ps1
- CheckHealth.ps1
- license.flf
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container t202 from image true:onprem-20.2.41144.41423-w1
45bbbc18499939705fc26ee9c0f8bb9d819aac9b9542b7da8417e65777be0e2d
Waiting for container t202 to be ready
Initializing...
Setting host.containerhelper.internal to 172.30.240.1 in container hosts file
Starting Container
Hostname is t202
PublicDnsName is mywebsite.com
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 594C24F0804F903AE5A66C3A1B82E1F33E2EA4BF
DNS identity mywebsite.com
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting EnableTaskScheduler to True
Setting PublicODataBaseUrl to https://mywebsite.com/t202rest/odata
Setting PublicSOAPBaseUrl to https://mywebsite.com/t202soap/ws
Setting PublicWebBaseUrl to https://mywebsite.com/t202
Starting Service Tier
CertificateThumprint 594C24F0804F903AE5A66C3A1B82E1F33E2EA4BF
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: t202
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\t202
Create the application pool t202
Create website: NavWebApplicationContainer with SSL
Update configuration: navsettings.json
Done Configuring Web Client
Using license file 'c:\run\my\license.flf'
Import License
Creating http download site
Setting SA Password and enabling SA
Creating Admin as SQL User and add to sysadmin
Creating SUPER user
Container IP Address: 172.30.247.190
Container Hostname  : t202
Container Dns Name  : mywebsite.com
Web Client          : https://mywebsite.com/t202/
Dev. Server         : https://mywebsite.com
Dev. ServerInstance : BC
Setting t202 to 172.30.247.190 in host hosts file

Files:
http://mywebsite.com:8080/ALLanguage.vsix
http://mywebsite.com:8080/certificate.cer

Container Total Physical Memory is 16.0Gb
Container Free Physical Memory is 0.8Gb

Initialization took 49 seconds
Ready for connections!
Reading CustomSettings.config from t202
Container t202 successfully created
Because of Traefik, the following URLs need to be used when accessing the container from outside your Docker host:
Web Client:        https://mywebsite.com/t202
SOAP WebServices:  https://mywebsite.com/t202soap
OData WebServices: https://mywebsite.com/t202rest
Dev Service:       https://mywebsite.com/t202dev
Snapshot Service:  https://mywebsite.com/t202snap
File downloads:    https://mywebsite.com/t202dl

Use:
Get-BcContainerEventLog -containerName t202 to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName t202 to get debug information about the container
Enter-BcContainer -containerName t202 to open a PowerShell prompt inside the container
Remove-BcContainer -containerName t202 to remove the container again
docker logs t202 to retrieve information about URL's again
Backing up CRONUS to C:\ProgramData\BcContainerHelper\Extensions\t202\database.bak
BcContainerHelper is version 4.0.5
BcContainerHelper is running as administrator
Hyper-V is Disabled
UsePsSession is True
Host is Microsoft Windows Server 2019 Datacenter - ltsc2019
Docker Client Version is 20.10.17
Docker Server Version is 20.10.17
Removing Session t210
Removing container t210
Removing entries from hosts
Removing t210 from container hosts file
Removing t210-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\t210
Fetching all docker images
Fetching all docker volumes
ArtifactUrl and ImageName specified
Image true:onprem-21.0.46256.46853-w1-nodb already exists
Enabling SSL as otherwise all clients will see mixed HTTP / HTTPS request, which will cause problems e.g. on the mobile and modern windows clients
Using image true:onprem-21.0.46256.46853-w1-nodb
PublicDnsName is mywebsite.com
Disabling Health Check (always report healthy)
Creating Container t210
Style: onprem
Multitenant: No
Version: 21.0.46256.46853
Platform: 21.0.46384.46844
Generic Tag: 1.0.2.13
Container OS Version: 10.0.17763.3532 (ltsc2019)
Host OS Version: 10.0.17763.3532 (ltsc2019)
Using process isolation
Using locale en-US
Adding special CheckHealth.ps1 to enable Traefik support
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file https://myazureblob.core.windows.net/license.flf
Downloading C:\ProgramData\BcContainerHelper\Extensions\t210\my\license.flf
Additional Parameters:
-e webserverinstance=t210
-e publicdnsname=mywebsite.com
-l "traefik.protocol=https"
-l "traefik.web.frontend.rule=PathPrefix:/t210"
-l "traefik.web.port=443"
-l "traefik.soap.frontend.rule=PathPrefix:/t210soap;ReplacePathRegex: ^/t210soap(.*) /BC$1"
-l "traefik.soap.port=7047"
-l "traefik.rest.frontend.rule=PathPrefix:/t210rest;ReplacePathRegex: ^/t210rest(.*) /BC$1"
-l "traefik.rest.port=7048"
-l "traefik.dev.frontend.rule=PathPrefix:/t210dev;ReplacePathRegex: ^/t210dev(.*) /BC$1"
-l "traefik.dev.port=7049"
-l "traefik.snap.frontend.rule=PathPrefix:/t210snap;ReplacePathRegex: ^/t210snap(.*) /BC$1"
-l "traefik.snap.port=7083"
-l "traefik.dl.frontend.rule=PathPrefixStrip:/t210dl"
-l "traefik.dl.port=8080"
-l "traefik.dl.protocol=http"
-l "traefik.enable=true"
-l "traefik.frontend.entryPoints=https"
--env customNavSettings=EnableTaskScheduler=True,PublicODataBaseUrl=https://mywebsite.com/t210rest/odata,PublicSOAPBaseUrl=https://mywebsite.com/t210soap/ws,PublicWebBaseUrl=https://mywebsite.com/t210
Files in C:\ProgramData\BcContainerHelper\Extensions\t210\my:
- AdditionalOutput.ps1
- CheckHealth.ps1
- license.flf
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container t210 from image true:onprem-21.0.46256.46853-w1-nodb
28f85dd2a6d70476dff61c0007a0ed348da91a146bb44f81e59ae4929f12f2f6
Waiting for container t210 to be ready
Initializing...
Setting host.containerhelper.internal to 172.30.240.1 in container hosts file
Starting Container
Hostname is t210
PublicDnsName is mywebsite.com
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Using Database .bak file 'C:\ProgramData\BcContainerHelper\Extensions\t202\database.bak'
Using database server localhost\SQLEXPRESS
Setting CompatibilityLevel for mydatabase on localhost\SQLEXPRESS
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 644A8E3554EEA605FC884A1614BDE0C129FB5A17
DNS identity mywebsite.com
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting EnableTaskScheduler to True
Setting PublicODataBaseUrl to https://mywebsite.com/t210rest/odata
Setting PublicSOAPBaseUrl to https://mywebsite.com/t210soap/ws
Setting PublicWebBaseUrl to https://mywebsite.com/t210
Starting Service Tier
Failed to start service 'Dynamics 365 Business Central Server [BC] (MicrosoftDynamicsNavServer$BC)'.
at <ScriptBlock>, C:\Run\navstart.ps1: line 172
at <ScriptBlock>, C:\Run\start.ps1: line 384
at <ScriptBlock>, <No file>: line 1Error
Initializing...
Setting host.containerhelper.internal to 172.30.240.1 in container hosts file
Starting Container
Hostname is t210
PublicDnsName is mywebsite.com
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Using Database .bak file 'C:\ProgramData\BcContainerHelper\Extensions\t202\database.bak'
Using database server localhost\SQLEXPRESS
Setting CompatibilityLevel for mydatabase on localhost\SQLEXPRESS
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 644A8E3554EEA605FC884A1614BDE0C129FB5A17
DNS identity mywebsite.com
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting EnableTaskScheduler to True
Setting PublicODataBaseUrl to https://mywebsite.com/t210rest/odata
Setting PublicSOAPBaseUrl to https://mywebsite.com/t210soap/ws
Setting PublicWebBaseUrl to https://mywebsite.com/t210
Starting Service Tier
Failed to start service 'Dynamics 365 Business Central Server [BC] (MicrosoftDynamicsNavServer$BC)'.
at <ScriptBlock>, C:\Run\navstart.ps1: line 172
at <ScriptBlock>, C:\Run\start.ps1: line 384
at <ScriptBlock>, <No file>: line 1
New-BCContainer Telemetry Correlation Id: 77dcbb31-ec55-4614-9257-45cc9b94583e
Initialization of container t210 failed
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\4.0.5\ContainerHandling\Wait-NavContainerReady.ps1:42 char:17
+ ...             throw "Initialization of container $containerName failed" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Initialization of container t210 failed:String) [], RuntimeException
    + FullyQualifiedErrorId : Initialization of container t210 failed
...

Screenshots If applicable, add screenshots to help explain your problem.

Additional context

freddydk commented 1 year ago

You can use Get-BcContainerEventLog to download the log and see what the problem is.

kine commented 1 year ago

I have a same problem in our upgrade script. I get this error>

image

When I try to mount tenant from BCv20 to service tier with technically updated BCv20 app to BCv21 platform.

I think this will be a platform problem, not bccontainerhelper problem....

catadumitru commented 1 year ago

I have a same problem in our upgrade script. I get this error>

image

When I try to mount tenant from BCv20 to service tier with technically updated BCv20 app to BCv21 platform.

I think this will be a platform problem, not bccontainerhelper problem....

Yes, I got the same error in the eventlog. I thought maybe it's not a platform problem because I couldn't find anyone else reporting it.

How is everyone else upgrading onprem? v21 has been out for almost 1 month. I haven't had the time to test an upgrade without bccontainerhelper yet.

kine commented 1 year ago

Have found it on yammer, no reaction, posted on September 16. https://www.yammer.com/dynamicsnavdev/#/Threads/show?threadId=1918775220314112

freddydk commented 1 year ago

Let's take the discussion on Yammer - and if anything need to change in the docker generic image - I will fix that. I have tagged Nikola on Yammer to see

PooyaKharamesh commented 1 year ago

There is a missing step (task 7) in your technical upgrade. A recompilation of apps is needed in order to generate the right metadata. here you can find all the steps Technical Upgrade to Version 19 - Business Central | Microsoft Learn

Here is the missing step https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/upgrade/upgrade-technical-upgrade-v19#task-7-recompile-published-extensions

Please follow the docs and let us know if you face any issues

freddydk commented 1 year ago

I will have a look at how we can change this in the generic image. probably by tomorrow or over the weekend.

freddydk commented 1 year ago

The technical upgrade process is described here: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/upgrade/upgrade-technical-upgrade-v21

The only step which is automatic in Docker (and has always been) is the NavAppDatabaseConversion (step 5)

The pre-steps and post-steps needs to be done - and for the 20 -> 21 upgrade this is different. This script performs a number of the steps of the technical upgrade list above (until step #9) - you will still have to perform #10 and #11 (Add-Ins upgrade) - but you get the picture... Only thing that I didn't find in the todo-list or things linked from that is the NavEwsWrapper replacement below.

$auth = "UserPassword"
$containerName = "bcserver"

$artifactUrl = get-bcartifacturl -country us
$credential = New-Object pscredential -ArgumentList 'admin', $PasswordSecret.SecretValue
$artifactUrl = "https://bcartifacts.azureedge.net/onprem/20.2.41144.41423/w1"
$containerName = "t202"
New-BCContainer -accept_eula `
                -doNotCheckHealth `
                -updateHosts `
                -containerName $containerName `
                -artifactUrl $artifactUrl `
                -auth $auth `
                -enableTaskScheduler `
                -Credential $credential

# Get Apps in dependency order
$appsJson = (Get-BcContainerAppInfo -containerName $containerName -sort DependenciesFirst).Name | ConvertTo-Json

Invoke-ScriptInBcContainer -containerName $containerName -scriptblock { Param($appsJson)
    $apps = $appsJson | ConvertFrom-Json
    [Array]::Reverse($apps)
    $apps | ForEach-Object { 
        Write-Host "Uninstalling $_"
        Uninstall-NAVApp -ServerInstance $serverInstance -Name $_ -Force
    }
    Get-NAVAppInfo -ServerInstance $serverInstance -SymbolsOnly | ForEach-Object {
        Write-Host "Unpublishing $($_.Name)"
        Unpublish-NAVApp -ServerInstance $serverInstance -Name $_.Name
    }

    $addInsFolder = "c:\programData\BcContainerHelper\Extensions\v20Add-Ins"
    if (!(Test-Path $addInsFolder)) {
        New-Item -Path $addInsFolder -ItemType Directory | Out-Null
        Copy-Item -Path 'C:\Program Files\Microsoft Dynamics NAV\200\Service\Add-Ins\TimeLine' -Destination $addInsFolder -Recurse -Force
        Copy-Item -Path 'C:\Program Files\Microsoft Dynamics NAV\200\Service\Add-Ins\PingPong' -Destination $addInsFolder -Recurse -Force
        New-Item -Path "$addInsFolder\NavEwsWrapper20" -ItemType Directory | Out-Null
        Copy-Item -Path 'C:\Program Files\Microsoft Dynamics NAV\200\Service\Add-Ins\NavEwsWrapper\*.dll' -Destination "$addInsFolder\NavEwsWrapper20" -Recurse -Force
    }
} -argumentList $appsJson

Backup-BcContainerDatabases $containerName

$artifactUrl = "https://bcartifacts.azureedge.net/onprem/21.0.46256.46853/w1"
$containerName = "t210"
New-BCContainer -accept_eula `
                -doNotCheckHealth `
                -updateHosts `
                -containerName $containerName `
                -artifactUrl $artifactUrl `
                -auth $auth `
                -enableTaskScheduler `
                -Credential $credential `
                -additionalParameters @("--volume ""$($bcContainerHelperConfig.HostHelperFolder)\Extensions\v20Add-Ins:c:\run\Add-Ins""") `
                -bakFile "$($bcContainerHelperConfig.HostHelperFolder)\Extensions\t202\database.bak"

Invoke-ScriptInBcContainer -containerName $containerName -scriptBlock { Param($appsJson)
    Remove-Item -path "C:\Program Files\Microsoft Dynamics NAV\210\Service\Add-ins\NavEwsWrapper" -Recurse -Force
    $apps = $appsJson | ConvertFrom-Json
    $apps | ForEach-Object {
        Write-Host "Repairing $_"
        Repair-NAVApp -ServerInstance $serverInstance -Name $_ | Out-Null
    }
    Restart-NavServerInstance -serverInstance $serverInstance
    Sync-NAVTenant -ServerInstance $serverInstance -Tenant default -Mode Sync -Force
    $apps | ForEach-Object {
        Write-Host "Sync'ing $_"
        Sync-NAVApp -ServerInstance $serverInstance -Name $_ | Out-Null
    }
    $apps | ForEach-Object {
        Write-Host "Installing $_"
        Install-NAVApp -ServerInstance $serverInstance -Name $_ | Out-Null
    }
} -argumentList $appsJson

In 22 there will probably be different steps in a todo list like this.

catadumitru commented 1 year ago

Thanks for the reply, I've been sick the last few days and didn't manage to post my findings:

I've managed to create a v21container with a v20db if I first removed all apps and saved it. After that my old script for upgrading worked. - all is fine.

I didn't manage to use the Repair-NAVApp function like in your script. There are no apps to repair...

palmerich commented 1 year ago

I've managed to create a v21container with a v20db if I first removed all apps and saved it. After that my old script for >upgrading worked. - all is fine. I didn't manage to use the Repair-NAVApp function like in your script. There are no apps to repair...

I had the same problem yesterday in an OnPrem customer update 20.4 to 21.1. I read here that you unpublished all extensions and it went through then. So I tried that - and heureka. Afterwards just had to publish and install all extensions. No negative impact according to the application consultants (I am tech). Thanks for your entry, [catadumitru] - that helped!

catadumitru commented 1 year ago

Glad it helped. I've only used it for dev/test environments but, if it works fine at customers that's great.

anilpardesi commented 1 year ago

Can you please update which stage we need Publish/Install unpblished apps?

freddydk commented 1 year ago

Can you please update which stage we need Publish/Install unpblished apps?

It is in the script above - you need to uninstall and unpublish before backing up the 20.x database - and then republish and re-install after mounting the DB in 21.x

anilpardesi commented 1 year ago

Thanks Freddydk, That worked. I dont use Docker, thats why there was confusion.

DobbyNator94 commented 1 year ago

Sorry, but that can't be the answer.

When I have an BC20 database and want to use it on BC21/22.. I install first BC20 somewhere, unpublish all Apps and then on BC21/22 Invoke-NavApplicationDatabaseConversion?

In the past it worked like that: Copy the database (maybe BC18), Invoke-NavApplicationDatabaseConversion it with -force from BC20, start the instance without this page 8700 Base Application error and uninstall/unpublish all apps. And I have an fresh starting point on BC20.

Now you can't to that, because the Instance on BC22 doesn't get started because of that error and I can't unpublish the apps..

So whats the solution when I want use an old .bak from BC20 and want to use it under BC22 without first uninstalling/unpublishing all apps on the server instance? Thats a lot of extra work, especially when you have to do it for a lot of databases and you want to keep them like they are.

I've done the following to uninstall / unpublish the apps from the bc20 databases:

Here is the script:


$objektarray = @(
'database1'
'database2'
)

foreach($objekt in $objektarray) {
    $ServiceInstanceName = "BC200"
    Set-NAVServerConfiguration -ServerInstance $ServiceInstanceName -KeyName "DatabaseServer" -KeyValue "DATABASESERVER"
Set-NAVServerConfiguration -ServerInstance $ServiceInstanceName -KeyName "DatabaseInstance" -KeyValue "DATABASESERVERINSTANCE"
    Set-NAVServerConfiguration -ServerInstance $ServiceInstanceName -KeyName "DatabaseName" -KeyValue "$objekt"
    Restart-NAVServerInstance -ServerInstance $ServiceInstanceName

    do {
    $i = $i + 1
    try {
        Get-NAVAppInfo -ServerInstance $ServiceInstanceName | % { Uninstall-NAVApp -ServerInstance $ServiceInstanceName -Name $_.Name -Version $_.Version -Force}
        Get-NAVAppInfo -ServerInstance $ServiceInstanceName | % { Unpublish-NAVApp -ServerInstance $ServiceInstanceName -Name $_.Name -Version $_.Version }
    }
    catch {
    }

    $Temp = if (Get-NAVAppInfo -ServerInstance $ServiceInstanceName | % {$_.Name}) {"True"}else{"False"}

} until (($Temp -eq "False") -or ($i -eq 50))

}

And then you can invoke the database to BC22 and start the service tier without problems.

Hope this can help someone.

best regards, Robin