microsoft / navcontainerhelper

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

New-NAVDatabase in v24 no longer works with external sql - cannot create v24 containers with external #3541

Open kevindstanley opened 3 months ago

kevindstanley commented 3 months ago

Describe the issue Ultimately the problem represents itself when running New-BcContainer with external db paramaters, but I narrowed it down to the call inside of Restore-BcDatabaseFromArtifacts.ps1 (which inside of start-job is incredibly difficult to debug). The line of code that causes the failure is the following on line 157. This is in the NAV Management DLL and I could not debug any further and it just immediately spits out an error on v24. https://github.com/microsoft/navcontainerhelper/blob/b68af9f05ff7ab0fb92ae5c7bc0ed355631701f8/Bacpac/Restore-BcDatabaseFromArtifacts.ps1#L157

The error shows up in what seems to be an unlikely area the Wait-NavContainerReady.ps1

Error restoring databases. Error was The system cannot find the file specified
at <ScriptBlock>, <No file>: line 110

Scripts used to create container and cause the issue

$containerName = "bctest"
$databaseCredential = Get-Credential
$containerCredential = Get-Credential

# v24 DOES NOT WORK
$artifactUrl = "https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.0.16410.19590/us"

# v23 DOES WORK
# $artifactUrl = "https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/23.5.16502.19600/us"

$licenseFile = "C:\workpath\license\latest.bclicense"

$databaseParams = @{
    "databaseServer"     = "ADESKTOPNAME"
    "databaseInstance"   = ""
    "databasePrefix"     = "$($containerName)-"
    "databaseName"       = "CRONUS"
    "databaseCredential" = $databaseCredential
    "multitenant"        = $true
}

New-BcContainer @databaseParams -replaceExternalDatabases `
    -accept_eula `
    -containerName "$containerName" `
    -credential $containerCredential `
    -auth UserPassword `
    -artifactUrl $artifactUrl `
    -enableTaskScheduler `
    -licenseFile $licenseFile `
    -updateHosts `
    -assignPremiumPlan `
    -accept_outdated `
    -memoryLimit "12G" `
    -shortcuts None `
    -isolation process 

Full output of scripts

Running on Windows, PowerShell 5.1.22621.2506
BcContainerHelper is version 6.0.17
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows 11 Pro - 10.0.22631.3447
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is never
UseSslForWinRmSession is True
Docker Client Version is 20.10.21
Docker Server Version is 20.10.21
Removing Session bctest24
Removing container bctest24
Removing entries from hosts
Removing bctest24 from container hosts file
Removing bctest24-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\bctest24
Starting Database Restore job from https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.0.16410.19590/us
C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\Import-BcContainerHelper.ps1
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2022
Creating Container bctest24
Style: sandbox
Multitenant: Yes
Version: 24.0.16410.19590
Platform: 24.0.19514.0
Generic Tag: 1.0.2.20
Container OS Version: 10.0.20348.2402 (ltsc2022)
Host OS Version: 10.0.22631.3447 (23H2)
Using process isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file C:\workpath\license\latest.bclicense
Additional Parameters:
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\bctest24\my:
- AdditionalOutput.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupDatabase.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container bctest24 from image mcr.microsoft.com/businesscentral:ltsc2022
b5631b4fbf1581fc3025df286282858cf83d83cbcf2a7dfa6ea8b160958eb4fa
Waiting for container bctest24 to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.0.16410.19590/us
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.0.16410.19590\us, platformArtifactPath=c:\dl\sandbox\24.0.16410.19590\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.0.16410.19590\us\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.0.16410.19590\platform\ServiceTier\Program Files
c:\dl\sandbox\24.0.16410.19590\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.0.16410.19590\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.0.16410.19590\platform
c:\dl\sandbox\24.0.16410.19590\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.0.16410.19590\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.0.16410.19590\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.0.16410.19590\us\Extensions
Copying Applications
C:\dl\sandbox\24.0.16410.19590\platform\Applications
Copying Applications.US
C:\dl\sandbox\24.0.16410.19590\us\Applications.US
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 6 seconds
Installation complete
Initializing...
Setting host.docker.internal to 192.168.1.20 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.1.20 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.29.16.1 in container hosts file
Starting Container
Hostname is bctest24
PublicDnsName is bctest24
Using NavUserPassword Authentication
Error restoring databases. Error was The system cannot find the file specified
at <ScriptBlock>, <No file>: line 110Error
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.0.16410.19590/us
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.0.16410.19590\us, platformArtifactPath=c:\dl\sandbox\24.0.16410.19590\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.0.16410.19590\us\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.0.16410.19590\platform\ServiceTier\Program Files
c:\dl\sandbox\24.0.16410.19590\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.0.16410.19590\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.0.16410.19590\platform
c:\dl\sandbox\24.0.16410.19590\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.0.16410.19590\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.0.16410.19590\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.0.16410.19590\us\Extensions
Copying Applications
C:\dl\sandbox\24.0.16410.19590\platform\Applications
Copying Applications.US
C:\dl\sandbox\24.0.16410.19590\us\Applications.US
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 6 seconds
Installation complete
Initializing...
Setting host.docker.internal to 192.168.1.20 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.1.20 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.29.16.1 in container hosts file
Starting Container
Hostname is bctest24
PublicDnsName is bctest24
Using NavUserPassword Authentication
Error restoring databases. Error was The system cannot find the file specified
at <ScriptBlock>, <No file>: line 110
New-BcContainer Telemetry Correlation Id: fc82fe96-73fe-4549-abf1-f62b85f33430
Initialization of container bctest24 failed
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Wait-NavContainerReady.ps1:42 char:17
+ ...             throw "Initialization of container $containerName failed" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Initialization ...bctest24 failed:String) [], RuntimeException
    + FullyQualifiedErrorId : Initialization of container bctest24 failed
freddydk commented 3 months ago

Works fine here Do you have PowerShell 7.4 installed on the host machine? all cmdlets of BC24 requires PS7

freddydk commented 3 months ago

and the reason why this shows in Waitforcontainerready is that the database restore is done in a background job running on the host, while the container is being created (and the host is waiting for the container to be created). During container creation the container will stop when it needs the database and wait for that process to be complete before continuing Cumbersome - but saves some time with larger databases.

mkay18 commented 3 months ago

Similar Issue in the same spot.
Latest BC24, SQL2019 on WS2019 on host PS7.4, SqlServer Module installed (22.2), Latest BCContainerHelper installed (18). added SSL cert to SQL, Set SQL to listen on all ports, In the same spot as Kevindstanley, but different error:

Using NavUserPassword Authentication
Error restoring databases. Error was Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.4.2.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at <ScriptBlock>, <No file>: line 42
New-BcContainer Telemetry Correlation Id: 4e20ceae-2ec5-4b40-a892-a6afa8c80bde
mkay18 commented 3 months ago

BTW, if we remove the -replaceexternaldatabases (just for fun?) we fail on import encryption key (see #3247 ).... Of course, technically the database doesn't yet exist.... But, maybe that helps shed some light on what's happening?

Using NavUserPassword Authentication
Import Encryption Key
Import-NAVEncryptionKey: 
Line |
  15 |      $output = Import-NAVEncryptionKey @cmdletArgs;
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot establish a connection to the SQL Server/Database.

This could be due to one of the following reasons:

* SQL Server is not started.
* The database does not exist.
* Proper permissions have not been given to the NAV Server Account.

Try again later or contact your system administrator.

at <ScriptBlock>, C:\Run\SetupDatabase.ps1: line 152
at <ScriptBlock>, C:\Run\navstart.ps1: line 141
at <ScriptBlock>, C:\Run\start.ps1: line 390
at <ScriptBlock>, <No file>: line 1Error
freddydk commented 3 months ago

Try to run this on the host:

Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl -databaseServer $databaseServer -databaseInstance $databaseInstance -databasePrefix $databasePrefix -databaseName $databaseName -multitenant:$multitenant

Maybe that will give you a better indication as to what goes wrong?

(That is basically what runs behind the scenes when using -replaceexternaldatabases)

mkay18 commented 3 months ago

Hi Freddy. Tried direct DB restore:


$databasePrefix = 'NTN10BC24-'
$artifactUrl = Get-BcArtifactUrl -country 'CA' -select 'latest'
$databaseServer = 'host.containerhelper.internal'
$databaseInstance = ''
$databaseName = 'CRONUS'

Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl `
    -databaseServer $databaseServer `
    -databaseInstance $databaseInstance `
    -databasePrefix $databasePrefix `
    -databaseName $databaseName `
    -multitenant:$true

Same result... here's the output:


Starting Database Restore job from https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.1.18927.20124/ca
C:\Users\mkulik\Documents\PowerShell\Modules\BcContainerHelper\6.0.18\Import-BcContainerHelper.ps1
BcContainerHelper version 6.0.18
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 7.4.2
Downloading Artifacts https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.1.18927.20124/ca
Downloading artifact /sandbox/24.1.18927.20124/ca
Downloading C:\Users\mkulik\AppData\Local\Temp\e30f29d4-a557-4c09-9db5-f1e3f9b0e4c5.zip
Unpacking artifact to tmp folder using Expand-Archive
Downloading platform artifact /sandbox/24.1.18927.20124/platform
Downloading C:\Users\mkulik\AppData\Local\Temp\c952baf3-ba95-4b43-b804-690afe01e0f6.zip
Unpacking artifact to tmp folder using Expand-Archive
Downloading Prerequisite Components
Downloading c:\bcartifacts.cache\sandbox\24.1.18927.20124\platform\Prerequisite Components\IIS URL Rewrite Module\rewrite_2.0_rtw
_x64.msi
Downloading c:\bcartifacts.cache\sandbox\24.1.18927.20124\platform\Prerequisite Components\DotNetCore\DotNetCore.1.0.4_1.1.1-Wind
owsHosting.exe
Importing PowerShell module C:\bcartifacts.cache\sandbox\24.1.18927.20124\platform\ServiceTier\program files\Microsoft Dynamics N
AV\240\Service\Management\Microsoft.Dynamics.Nav.Management.dll
Restore-BcDatabaseFromArtifacts Telemetry Correlation Id: 90e2be00-142c-409b-873d-613132f39b19
Import-Module: C:\Users\mkulik\Documents\PowerShell\Modules\BcContainerHelper\6.0.18\Bacpac\Restore-BcDatabaseFromArtifacts.ps1:2
22:13
Line |
 222 |              $job | Receive-Job
     |              ~~~~~~~~~~~~~~~~~~
     | Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation,
     | Version=7.4.2.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
mkay18 commented 3 months ago

BTW I tested pinging host.containerhelper.internal from inside the (earlier) container and its perfect.

mkay18 commented 3 months ago

Remarkably, above DBRestore works perfectly in PS5.1:

PS C:\Windows\system32> #Import-module -name SQLServer -force
#Import-Module -name BCContainerHelper -force

$databasePrefix = 'NTN10BC24-'
$artifactUrl = Get-BcArtifactUrl -country 'CA' -select 'latest'
$databaseServer = '192.168.3.40'
$databaseInstance = ''
$databaseName = 'CRONUS'

Restore-BcDatabaseFromArtifacts -artifactUrl $artifactUrl `
    -databaseServer $databaseServer `
    -databaseInstance $databaseInstance `
    -databasePrefix $databasePrefix `
    -databaseName $databaseName `
    -multitenant:$true `
    -Verbose
Starting Database Restore job from https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.1.18927.20124/ca
C:\Program Files\WindowsPowerShell\Modules\BCContainerHelper\6.0.17\Import-BcContainerHelper.ps1
BcContainerHelper version 6.0.17
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.17763.5830
Downloading Artifacts https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.1.18927.20124/ca
Importing PowerShell module C:\bcartifacts.cache\sandbox\24.1.18927.20124\platform\ServiceTier\program files\Microsoft Dynamics NAV\240\Service\Management\Microso
ft.Dynamics.Nav.Management.dll
Restoring database NTN10BC24-tenant into D:\SQL\Databases\NTN10BC24
Exporting Application to NTN10BC24-CRONUS
Removing Application from NTN10BC24-tenant
Success

Will try to build container (in PS 7.4) without replacing external DB using this DB.

mkay18 commented 3 months ago

So no progress. Tried building the Container without the External DB replace enabled (because I restored the one above using PS5) using kevindstanley's sample script. tried with both auth Userpassword and Windows... same result... fails at Import-NavEncryptionKey. (Confirmed DB name is correct and I can ping host.containerhelper.internal)

BcContainerHelper is version 6.0.18
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows Server 2019 Standard - 10.0.17763.5830
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 20.10.9
Docker Server Version is 20.10.9
Removing Session NTN10BC24
Removing container NTN10BC24
Removing entries from hosts
Removing NTN10BC24 from container hosts file
Removing NTN10BC24-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\NTN10BC24
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2019
Creating Container NTN10BC24
Style: sandbox
Multitenant: Yes
Version: 24.1.18927.20124
Platform: 24.0.20090.0
Generic Tag: 1.0.2.20
Container OS Version: 10.0.17763.5696 (ltsc2019)
Host OS Version: 10.0.17763.5830 (ltsc2019)
Using hyperv isolation
Using locale en-CA
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file D:\DockerDVPFiles\BC-24-4830043.bclicense
Additional Parameters:
--expose 5986
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\NTN10BC24\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container NTN10BC24 from image mcr.microsoft.com/businesscentral:ltsc2019
a9e6097b246808303bfd7dc89d24459d42ab1d550f1688001d4c5032bbae09f5
Waiting for container NTN10BC24 to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.1.18927.20124/ca
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibraries
Only=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.1.18927.20124\ca, p
latformArtifactPath=c:\dl\sandbox\24.1.18927.20124\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.1.18927.20124\ca\Cro
nus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
WARNING: Waiting for service 'SQL Server (SQLEXPRESS) (MSSQL$SQLEXPRESS)' to
start...
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.1.18927.20124\platform\ServiceTier\Program Files
c:\dl\sandbox\24.1.18927.20124\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.1.18927.20124\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.1.18927.20124\platform
c:\dl\sandbox\24.1.18927.20124\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.1.18927.20124\ca\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.1.18927.20124\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.1.18927.20124\ca\Extensions
Copying Applications
C:\dl\sandbox\24.1.18927.20124\platform\Applications
Copying Applications.CA
C:\dl\sandbox\24.1.18927.20124\ca\Applications.CA
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 49 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 192.168.240.1 in container hosts file
Starting Container
Hostname is NTN10BC24
PublicDnsName is NTN10BC24
Using NavUserPassword Authentication
Import Encryption Key
Import-NAVEncryptionKey: 
Line |
  15 |      $output = Import-NAVEncryptionKey @cmdletArgs;
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot establish a connection to the SQL Server/Database.

This could be due to one of the following reasons:

* SQL Server is not started.
* The database does not exist.
* Proper permissions have not been given to the NAV Server Account.

Try again later or contact your system administrator.

at <ScriptBlock>, C:\Run\SetupDatabase.ps1: line 152
at <ScriptBlock>, C:\Run\navstart.ps1: line 141
at <ScriptBlock>, C:\Run\start.ps1: line 390
at <ScriptBlock>, <No file>: line 1Error
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.1.18927.20124/ca
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibraries
Only=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.1.18927.20124\ca, p
latformArtifactPath=c:\dl\sandbox\24.1.18927.20124\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.1.18927.20124\ca\Cro
nus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
WARNING: Waiting for service 'SQL Server (SQLEXPRESS) (MSSQL$SQLEXPRESS)' to
start...
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.1.18927.20124\platform\ServiceTier\Program Files
c:\dl\sandbox\24.1.18927.20124\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.1.18927.20124\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.1.18927.20124\platform
c:\dl\sandbox\24.1.18927.20124\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.1.18927.20124\ca\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.1.18927.20124\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.1.18927.20124\ca\Extensions
Copying Applications
C:\dl\sandbox\24.1.18927.20124\platform\Applications
Copying Applications.CA
C:\dl\sandbox\24.1.18927.20124\ca\Applications.CA
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 49 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 192.168.240.1 in container hosts file
Starting Container
Hostname is NTN10BC24
PublicDnsName is NTN10BC24
Using NavUserPassword Authentication
Import Encryption Key
Import-NAVEncryptionKey: 
Line |
  15 |      $output = Import-NAVEncryptionKey @cmdletArgs;
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot establish a connection to the SQL Server/Database.

This could be due to one of the following reasons:

* SQL Server is not started.
* The database does not exist.
* Proper permissions have not been given to the NAV Server Account.

Try again later or contact your system administrator.

at <ScriptBlock>, C:\Run\SetupDatabase.ps1: line 152
at <ScriptBlock>, C:\Run\navstart.ps1: line 141
at <ScriptBlock>, C:\Run\start.ps1: line 390
at <ScriptBlock>, <No file>: line 1
New-BcContainer Telemetry Correlation Id: 71beb643-3fec-460d-af5c-0e522524648e
Exception: C:\Users\mkulik\Documents\PowerShell\Modules\BcContainerHelper\6.0.18\ContainerHandling\Wait-NavContainerReady.ps1:42:
17
Line |
  42 |  …             throw "Initialization of container $containerName failed" …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Initialization of container NTN10BC24 failed 
freddydk commented 3 months ago

And SQL Server on the host is listening on all NIC's?

mkay18 commented 3 months ago

Yes. SQL was set to listen on all IPs and NICs. (And all of this works perfectly with BC23 and PS 5.1 on the same hardware.)

freddydk commented 3 months ago

Yeah, well - it works perfectly with 24.1 on my machine as well - so I am looking for differences...

mkay18 commented 3 months ago

Could it be that PS7.4 is missing some modules...? can you think of anything other than the SQLServer module that needs to be installed? I also tried to enable TLS1.2... but that made no difference. also added certificate to SQL.

freddydk commented 3 months ago

The entire creation of the container still runs PS5.1 inside the container, When you have restores the database locally - then the rest should just work.

mkay18 commented 3 months ago

Do you think the errors mentioned above are being thrown by the PS5.1 instance in the container? The restore DB issue (not working in PS7.4 but does work in PS5.1) is not happening inside a container, but using PS5.1 on the host is a workaround for that one. But it sounds like you think the inability to connect to SQL for the Import Encryption Key (NavEncryptionKey) is inside the container PS5.1 / Is that right? Does it help to know that the import encryption key takes a long time to error out?

kevindstanley commented 3 months ago

I ended up getting this working by installing PS 7.4. I write a lot of my code in VSCode and it was defaulting to PS 7, which doesn't work with bccontainerhelper - it needs to be running in PS 5.1 to start the commands at all.

Basically, after I installed PS 7.4, in vscode you can change the instance version that PS is running. Once I did that, you can change the default as well, so now when I open VSCode it opens in PS 5.1 and all seems to be back to working like normal for me.

mkay18 commented 3 months ago

interesting approach. I couldn't get it to work in the PS 5.1 ISE, so I tried your idea to switch the PS version in VSC to 5.1.... unfortunately, still getting the Import Key error. Also strange, I thought BCContainerHelper only worked with PS7.4, but it seemed to import ok when i tried it in VSC:

BcContainerHelper version 6.0.18
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.17763.5830
BcContainerHelper is version 6.0.18
BcContainerHelper is running as administrator
mkay18 commented 3 months ago

@kevindstanley holy smokes! So I tried your approach one more time, but this time I included the -replaceExternalDatabases to allow the script to overwrite the database i managed to install earlier..... It worked! Including setting up external IPs! No issue with retrieving the encryption key. Thanks! For others hoping to try this approach, you need to switch the PowerShell Session in VSC to the Powershell 5.1...

In VSC, open the Command Palette on Windows with Ctrl+Shift+P. Search for Session. Click on PowerShell: Show Session Menu. Choose the version of PowerShell you want to use from the list.

note that (in my case) "PowerShell (x64)" = 7.4 "Windows PowerShell (x64)" = 5.1

You can check the version using $PSVersionTable

Here are the links I used for reference in addition to @kevindstanley advice: https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/vscode/using-vscode?view=powershell-7.4 https://www.reddit.com/r/vscode/comments/fg0nzo/how_to_force_vsc_1411_to_load_powershell_51_and/ https://www.howtogeek.com/731885/how-to-check-the-powershell-version-in-windows-10/#:~:text=Key%20Takeaways,features%20you%20have%20access%20to.

By the way, I don't think this is the right approach overall, but it seems to be the only workaround I've found to get BC24 installed on a container with an external DB and IP address. (And of course, always appreciating @freddydk 's help)

@freddydk is is possible you are using the PS5.1 PS session in VSC as well?

freddydk commented 3 months ago

I have been running that test in PS5.1 (using PowerShell ISE) Will try it in PS7

BTW - I assume you have PS 7.4.1 (or .2)

mkay18 commented 3 months ago

yep. PS 7.4.2 in VSC. Actually, there was a specific reason why we originally went to PS7 that had something to do with BCContainerHelper and the external DB, but I can't find it in my notes.