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

Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. #3599

Open mati-own opened 1 month ago

mati-own commented 1 month ago

I want to create local multitenant environment (v24.2) on docker, I get an error as below

Using NavUserPassword Authentication
Error restoring databases. Error was Exception calling ".ctor" with "1" argument(s): "Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
at <ScriptBlock>, <No file>: line 110
New-BcContainer Telemetry Correlation Id: f7f7d4ac-cf57-44b4-b553-6b4240d3ae44

Scripts used to create container and cause the issue

 $containerName = ""
$credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String '' -AsPlainText -Force)
$artifactUrl = Get-BCArtifactUrl -country "dk" -version "24.2.20227.20460" -select Closest

$databaseSecurePassword = ConvertTo-SecureString -String '' -AsPlainText -Force

$databaseParams = @{
    "databaseServer" = '10.0.0.4'
    "databaseInstance" = ''
    "databasePrefix" = "$containerName-"
    "databaseName" = 'CRONUS'
    "databaseCredential" = New-Object pscredential 'sa', $databaseSecurePassword
    "multitenant" = $true
}

New-BcContainer @databaseParams -replaceExternalDatabases `
    -accept_eula `
    -artifactUrl $artifactUrl `
    -doNotCheckHealth `
    -usebestcontaineros `
    -containerName $containerName `
    -auth UserPassword `
    -Credential $credential `
    -licenseFile "" `
    -enableTaskScheduler `
    -updateHosts `
    -shortcuts CommonDesktopFolder `
    -memoryLimit 16G 

Full output of scripts

Host: Microsoft Windows Server 2022 Datacenter Azure Edition
Docker: 27.0.3
PowerShell: 7.4.3
PS Module, BcContainerHelper: 6.0.20-preview1214
PS Module, SQLServer:  22.2
...
freddydk commented 1 month ago

Please supply the full output of the scripts

freddydk commented 1 month ago

Also, does it work when you run this on PowerShell 5 on the host?

spncrgr commented 1 month ago

I'm experiencing a similar issue while attempting to restore a backup of my BC Online database to a container.

As you requested of @mati-own, I tried running all the scripts in PowerShell 5 but ultimately failed because the SQL Server certificate was not trusted. I'm sure there's a way around that, but I'm too exhausted to investigate it further tonight. The full output of that script is also below.

Here's the script I'm running to create the container:

$containerName = "BC243"
$auth = "UserPassword"
$credential = New-Object pscredential `
    -ArgumentList 'admin', $passwordSecret.SecretValue
$licenseFile = Join-Path $PSScriptRoot "######.bclicense"
$databaseParams = @{
    "databaseServer"     = "localhost"
    "databaseInstance"   = "BCSERVER"
    "databasePrefix"     = "$($containerName)-"
    "databaseName"       = "CRONUS"
    "databaseCredential" = New-Object pscredential `
        -ArgumentList 'sa', $passwordSecret.SecretValue
    "multitenant"        = $true
}
New-BcContainer @databaseParams -replaceExternalDatabases `
    -accept_eula `
    -containerName "$containerName" `
    -credential $credential `
    -auth $auth `
    -artifactUrl $artifactUrl `
    -enableTaskScheduler `
    -isolation hyperv `
    -licenseFile $licenseFile

And here is the full output, running on PowerShell 7.4.4:

BcContainerHelper is version 6.0.20-preview1214
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows 11 Enterprise - 10.0.22631.3880
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 27.0.1
Docker Server Version is 27.0.1
Removing Desktop shortcuts
Setting database BC243-tenant offline
Removing database BC243-tenant
Starting Database Restore job from https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.3.21374.21975/us
C:\Users\SpencerRoach\OneDrive - HomeSource Operations, LLC\Documents\PowerShell\Modules\BcContainerHelper\6.0.20\Import-BcContainerHelper.ps1
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2022-dev
Creating Container BC243
Style: sandbox
Multitenant: Yes
Version: 24.3.21374.21975
Platform: 24.0.21889.0
Generic Tag: 1.0.2.36-dev
Container OS Version: 10.0.20348.2527 (ltsc2022)
Host OS Version: 10.0.22631.3880 (23H2)
Using hyperv isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file D:\Playground\BCDocker\######.bclicense
Additional Parameters:                                                                                                  
--expose 5986
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\BC243\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupDatabase.ps1
- SetupVariables.ps1
- updatecontainerhosts.ps1
Creating container BC243 from image mcr.microsoft.com/businesscentral:ltsc2022-dev
be274a95ac42e9a8a4a5d44db0699b8ad4ddca178bbc43ca54bb175287c63f28
Waiting for container BC243 to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.3.21374.21975/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.3.21374.21975\us, platformArtifactPath=c:\dl\sandbox\24.3.21374.21975\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.3.21374.21975\us\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\Program Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.3.21374.21975\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.3.21374.21975\platform
c:\dl\sandbox\24.3.21374.21975\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.3.21374.21975\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.3.21374.21975\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.3.21374.21975\us\Extensions
Copying Applications
C:\dl\sandbox\24.3.21374.21975\platform\Applications
Copying Applications.US
C:\dl\sandbox\24.3.21374.21975\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 8 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.19.112.1 in container hosts file
Starting Container
Hostname is BC243
PublicDnsName is BC243
Using NavUserPassword Authentication
Waiting for database creation to finish
Error restoring databases. Error was Exception calling ".ctor" with "1" argument(s): "Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
at <ScriptBlock>, <No file>: line 110Error
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.3.21374.21975/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.3.21374.21975\us, platformArtifactPath=c:\dl\sandbox\24.3.21374.21975\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.3.21374.21975\us\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\Program Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.3.21374.21975\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.3.21374.21975\platform
c:\dl\sandbox\24.3.21374.21975\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.3.21374.21975\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.3.21374.21975\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.3.21374.21975\us\Extensions
Copying Applications
C:\dl\sandbox\24.3.21374.21975\platform\Applications
Copying Applications.US
C:\dl\sandbox\24.3.21374.21975\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 8 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.19.112.1 in container hosts file
Starting Container
Hostname is BC243
PublicDnsName is BC243
Using NavUserPassword Authentication
Waiting for database creation to finish
Error restoring databases. Error was Exception calling ".ctor" with "1" argument(s): "Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
at <ScriptBlock>, <No file>: line 110
New-BcContainer Telemetry Correlation Id: 1970b811-e121-4729-a119-bf8ebe0a181f
Exception: C:\Users\SpencerRoach\OneDrive - HomeSource Operations, LLC\Documents\PowerShell\Modules\BcContainerHelper\6.0.20\ContainerHandling\Wait-NavContainerReady.ps1:42:17
Line |
  42 |  …             throw "Initialization of container $containerName failed" …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Initialization of container BC243 failed

And here is the full output running on PowerShell 5:

BcContainerHelper is version 6.0.19
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows 11 Enterprise - 10.0.22631.3880
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 27.0.1
Docker Server Version is 27.0.1
Removing Session BC243
Removing container BC243
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\BC243
New-BcContainer Telemetry Correlation Id: 98d7953d-4e82-4698-ba1d-a5960e91fd28
Invoke-SqlCmd : A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate
chain was issued by an authority that is not trusted.)
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\Bacpac\Remove-BcDatabase.ps1:41 char:16
+     $dbFiles = Invoke-SqlCmd `
+                ~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
    + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
spncrgr commented 1 month ago

Quick update...

I searched issues for help on the SQL Server cert issue (which I should have done to begin with, but again, it's been a long day). In any case, I found issue #3572, which prompted me to update BcContainerHelper to the preview version for PowerShell 5. That enabled me to move past the certificate issue.

I did not get the same error on PowerShell 5.1 as 7.4.4 (Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly).

However, I received another db-related error on the Import Encryption Key step. The error is Cannot establish a connection to the SQL Server/Database. One other thing to note is the BC243-CRONUS and BC243-tenant databases were both created.

Here's the full output of this latest attempt:

BcContainerHelper is version 6.0.20-preview1214
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows 11 Enterprise - 10.0.22631.3880
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 27.0.1
Docker Server Version is 27.0.1
Removing Session BC243
Removing container BC243
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\BC243
Setting database BC243-tenant offline
Removing database BC243-tenant
Setting database BC243-CRONUS offline
Removing database BC243-CRONUS
Starting Database Restore job from https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.3.21374.21975/us
C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.20\Import-BcContainerHelper.ps1
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2022-dev
Creating Container BC243
Style: sandbox
Multitenant: Yes
Version: 24.3.21374.21975
Platform: 24.0.21889.0
Generic Tag: 1.0.2.36-dev
Container OS Version: 10.0.20348.2527 (ltsc2022)
Host OS Version: 10.0.22631.3880 (23H2)
Using hyperv isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file D:\Playground\BCDocker\######.bclicense
Additional Parameters:
--expose 5986
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\BC243\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupDatabase.ps1
- SetupVariables.ps1
- updatecontainerhosts.ps1
Creating container BC243 from image mcr.microsoft.com/businesscentral:ltsc2022-dev
f1e74d9eb832ea39444f3f9c618587495ff861940e111be8f8c1f0a852c1a865
Waiting for container BC243 to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.3.21374.21975/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.3.21374.21975\us, platformArtifactPath=c:\dl\sandbox\24.3.21374.21975\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.3.21374.21975\us\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\Program Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.3.21374.21975\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.3.21374.21975\platform
c:\dl\sandbox\24.3.21374.21975\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.3.21374.21975\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.3.21374.21975\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.3.21374.21975\us\Extensions
Copying Applications
C:\dl\sandbox\24.3.21374.21975\platform\Applications
Copying Applications.US
C:\dl\sandbox\24.3.21374.21975\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 8 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.19.112.1 in container hosts file
Starting Container
Hostname is BC243
PublicDnsName is BC243
Using NavUserPassword Authentication
Waiting for database creation to finish
Success
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\my\SetupDatabase.ps1: line 2
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.3.21374.21975/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.3.21374.21975\us, platformArtifactPath=c:\dl\sandbox\24.3.21374.21975\platform, databasePath=, licenseFilePath=c:\dl\sandbox\24.3.21374.21975\us\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\Program Files
c:\dl\sandbox\24.3.21374.21975\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.3.21374.21975\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.3.21374.21975\platform
c:\dl\sandbox\24.3.21374.21975\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.3.21374.21975\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.3.21374.21975\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.3.21374.21975\us\Extensions
Copying Applications
C:\dl\sandbox\24.3.21374.21975\platform\Applications
Copying Applications.US
C:\dl\sandbox\24.3.21374.21975\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 8 seconds
Installation complete
Initializing...
Setting host.containerhelper.internal to 172.19.112.1 in container hosts file
Starting Container
Hostname is BC243
PublicDnsName is BC243
Using NavUserPassword Authentication
Waiting for database creation to finish
Success
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\my\SetupDatabase.ps1: line 2
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: 2bcfec16-b3e7-4645-86b4-244006eb14bc
Initialization of container BC243 failed
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.20\ContainerHandling\Wait-NavContainerReady.ps1:42 char:17
+ ...             throw "Initialization of container $containerName failed" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Initialization of container BC243 failed:String) [], RuntimeException
    + FullyQualifiedErrorId : Initialization of container BC243 failed