microsoft / navcontainerhelper

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

New-BCContainer error - Access to the path 'C:\Run\Collation.txt' is denied. #2627

Closed ZacRyon closed 2 years ago

ZacRyon commented 2 years ago

Describe the issue When running the New-BCContainer cmdlet, I get this error: "Access to the path 'C:\run\Collation.txt' is denied."

Scripts used to create container and cause the issue

New-BCContainer `
    -accept_eula `
    -containerName $MyDevContainerName `
    -artifactUrl $MyArtifactUrl `
    -licenseFile $LicenseFile `
    -Auth NavUserPassword `
    -Credential $Credential `
    -updateHosts `
    -isolation hyperv `
    -multitenant `
    -includeAL `
    -UsecleanDatabase `
    -useNewDatabase `
    -assignPremiumPlan `
    -copyTables @('Add-in', 'Report Layout', 'Style Sheet') `
    -myscripts @("https://raw.githubusercontent.com/microsoft/nav-docker/master/override/issue2434/HelperFunctions.ps1") 

(The variables are not included, but set immediately before this command.)

Full output of scripts

PS C:\WINDOWS\system32> C:\Tools (FAME, BacPac)\BacPac Creation\2. NewSysOnlyContainer.ps1
BcContainerHelper is version 3.0.11
BcContainerHelper is running as administrator
Hyper-V is Enabled
UsePsSession is True
Host is Microsoft Windows 10 Pro - 21H1
Docker Client Version is 20.10.14
Docker Server Version is 20.10.14
Removing entries from hosts
Removing BC203US from container hosts file
Removing BC203US-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\BC203US
Fetching all docker images
Fetching all docker volumes
INFO: Windows 10 21H1/21H2 images are not yet available, using 2004 as these are found to work better than 20H2 on 21H1/21H2
Using image mcr.microsoft.com/businesscentral:10.0.19041.1415
Creating Container BC203US
Style: sandbox
Multitenant: Yes
Version: 20.3.42673.43456
Platform: 20.0.42653.43435
Generic Tag: 1.0.2.1
Container OS Version: 10.0.19041.1415 (2004)
Host OS Version: 10.0.19043.1826 (21H1)
Using hyperv isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Downloading C:\ProgramData\BcContainerHelper\Extensions\BC203US\my\HelperFunctions.ps1
Using license file C:\OD\OneDrive\Licenses\v20 - expires 30 Aug 2022.flf
Files in C:\ProgramData\BcContainerHelper\Extensions\BC203US\my:
- AdditionalOutput.ps1
- HelperFunctions.ps1
- license.flf
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container BC203US from image mcr.microsoft.com/businesscentral:10.0.19041.1415
ad2ac77888401f3db80007ba090a34ebd48ef84caee1ac211581f0d27cd052bd
Waiting for container BC203US to be ready
Using artifactUrl https://bcartifacts.azureedge.net/sandbox/20.3.42673.43456/us
Using installer from C:\Run\150-new
Installing Business Central
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\20.3.42673.43456\platform\ServiceTier\Program Files
c:\dl\sandbox\20.3.42673.43456\platform\ServiceTier\System64Folder
Copying PowerShell Scripts
c:\dl\sandbox\20.3.42673.43456\platform\WindowsPowerShellScripts\Cloud\NAVAdministration
c:\dl\sandbox\20.3.42673.43456\platform\WindowsPowerShellScripts\WebSearch
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Determining Database Collation from c:\dl\sandbox\20.3.42673.43456\us\BusinessCentral-US.bak
Restoring CRONUS Demo Database
Setting CompatibilityLevel for CRONUS on localhost\SQLEXPRESS
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Copying Web Client Files
c:\dl\sandbox\20.3.42673.43456\platform\WebClient\Microsoft Dynamics NAV
Copying Client Files
c:\dl\sandbox\20.3.42673.43456\platform\LegacyDlls\program files\Microsoft Dynamics NAV
c:\dl\sandbox\20.3.42673.43456\platform\LegacyDlls\program files\Microsoft Dynamics NAV
c:\dl\sandbox\20.3.42673.43456\platform\LegacyDlls\systemFolder
Copying ModernDev Files
c:\dl\sandbox\20.3.42673.43456\platform
c:\dl\sandbox\20.3.42673.43456\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\20.3.42673.43456\us\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\20.3.42673.43456\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\20.3.42673.43456\us\Extensions
Copying Applications
C:\dl\sandbox\20.3.42673.43456\platform\Applications
Copying Applications.US
C:\dl\sandbox\20.3.42673.43456\us\Applications.US
Starting Business Central Service Tier
Importing license file
Stopping Business Central Service Tier
Installation took 240 seconds
Installation complete
Initializing...
Setting host.docker.internal to 10.0.1.5 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 10.0.1.5 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.19.48.1 in container hosts file
Starting Container
Hostname is BC203US
PublicDnsName is BC203US
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint F6646ABA73BF16D2BEBF20BC3C00CD949698BC68
DNS identity BC203US
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Enabling Financials User Experience
Using license file 'c:\run\my\license.flf'
Import License
Creating http download site
Setting SA Password and enabling SA
Creating zac as SQL User and add to sysadmin
Creating SUPER user
Assign Premium plan for ZAC
Container IP Address: 172.19.62.50
Container Hostname  : BC203US
Container Dns Name  : BC203US
Web Client          : http://BC203US/BC/
Dev. Server         : http://BC203US
Dev. ServerInstance : BC
Setting BC203US to 172.19.62.50 in host hosts file

Files:
http://BC203US:8080/ALLanguage.vsix

WARNING: You are running a container which is 138 days old.
Microsoft recommends that you always run the latest version of our containers.

Container Total Physical Memory is 8.5Gb
Container Free Physical Memory is 6.4Gb

Initialization took 57 seconds
Ready for connections!
Reading CustomSettings.config from BC203US
Creating Desktop Shortcuts for BC203US
Extracting C:\Applications.US\Base Application.Source.zip
Creating .net Assembly Reference Folder for VS Code
Copying DLLs from C:\Windows\assembly to assemblyProbingPath
Copying DLLs from C:\Windows\Microsoft.NET\assembly to assemblyProbingPath
Copying DLLs from C:\Program Files\Microsoft Dynamics NAV\200\Service to assemblyProbingPath
Copying DLLs from C:\Program Files (x86)\Microsoft Dynamics NAV\200\RoleTailored Client to assemblyProbingPath
Copying DLLs from C:\Test Assemblies\Mock Assemblies to assemblyProbingPath
Copying DLLs from C:\Program Files (x86)\Open XML SDK to assemblyProbingPath
Stopping ServiceTier in order to replace database
Copying Database on localhost\SQLEXPRESS from CRONUS to mytempdb
Taking database CRONUS offline
Copying database files
Attaching files as new Database mytempdb
Putting database CRONUS back online
Removing Database CRONUS from localhost\SQLEXPRESS
Access to the path 'C:\run\Collation.txt' is denied.

Exception Script Stack Trace:
at <ScriptBlock>, <No file>: line 36

PowerShell Call Stack:
at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 71
at Clean-BcContainerDatabase, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\AppHandling\Clean-BcContainerDatabase.ps1: line 99
at New-BcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\ContainerHandling\New-NavContainer.ps1: line 2237
at <ScriptBlock>, C:\Tools (FAME, BacPac)\BacPac Creation\2. NewSysOnlyContainer.ps1: line 9

Container Free Physical Memory: 7.0Gb

Services in container BC203US:
- MicrosoftDynamicsNavServer$BC is Stopped
- MSSQL$SQLEXPRESS is Running

Relevant event log from container BC203US:
- 20220726 05:56:22 - MicrosoftDynamicsNAVClientWebClient

  Category: Microsoft.Dynamics.Nav.Client.Web.ThrottledSystemHealthChecker
  EventId: 0
  ConnectionId: 0HMJF4TRRIDTT
  RequestId: 0HMJF4TRRIDTT:00000006
  RequestPath: /BC/Health/System
  ActionId: 8d7f4212-2cae-431a-a7df-b0ea57227397
  ActionName: Microsoft.Dynamics.Nav.WebClient.Controllers.HealthController.System (Prod.Client.WebCoreApp)

  No IPEndpoints were found for host localhost.

  Exception: 
  System.ServiceModel.EndpointNotFoundException: No IPEndpoints were found for host localhost.
     at System.ServiceModel.Channels.SocketConnectionInitiator.ConnectAsync(Uri uri, TimeSpan timeout)
     at System.ServiceModel.Channels.BufferedConnectionInitiator.ConnectAsync(Uri uri, TimeSpan timeout)
     at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnectionAsync(TimeSpan timeout)
     at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpenAsync(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.OnOpenAsyncInternal(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan timeout)
     at System.Runtime.TaskHelpers.WaitForCompletion(Task task)
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.Runtime.TaskHelpers.CallActionAsync[TArg](Action`1 action, TArg argument)
     at System.ServiceModel.Channels.ServiceChannel.OnOpenAsync(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.OnOpenAsyncInternal(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.System.ServiceModel.IAsyncCommunicationObject.OpenAsync(TimeSpan timeout)
     at System.ServiceModel.Channels.CommunicationObject.OpenAsyncInternal(TimeSpan timeout)
     at System.Runtime.TaskHelpers.WaitForCompletion(Task task)
     at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
     at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout
)
     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation)
     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args)
     at generatedProxy_1.IsSystemHealthy()
     at Microsoft.Dynamics.Nav.Client.Web.SystemHealthChecker.<>c.<IsSystemHealthyAsync>b__2_0(IHealthService service) in s:\repo\src\Platform\Client\Web\Prod.Client.
WebCommon\Services\SystemHealth\SystemHealthChecker.cs:line 35
     at Microsoft.Dynamics.Nav.Client.Web.SimpleServerOperation.ExecuteCore[TResult,TChannel](RequestContext requestContext, ConnectionOptions serverConnectionOptions
, Func`2 operation, Func`3 operationWithContext, Func`2 localExceptionHandler, Int32 retryCount) in s:\repo\src\Platform\Client\Web\Prod.Client.WebCommon\Security\Sim
pleServerOperation.cs:line 283
     at Microsoft.Dynamics.Nav.Client.Web.SimpleServerOperation.Execute[TResult,TChannel](RequestContext requestContext, ConnectionOptions serverConnectionOptions, Fu
nc`2 operation, Func`2 localExceptionHandler) in s:\repo\src\Platform\Client\Web\Prod.Client.WebCommon\Security\SimpleServerOperation.cs:line 217
     at Microsoft.Dynamics.Nav.Client.Web.SystemHealthChecker.IsSystemHealthyAsync() in s:\repo\src\Platform\Client\Web\Prod.Client.WebCommon\Services\SystemHealth\Sy
stemHealthChecker.cs:line 35
     at Microsoft.Dynamics.Nav.Client.Web.ThrottledSystemHealthChecker.<IsSystemHealthyAsync>b__6_0() in s:\repo\src\Platform\Client\Web\Prod.Client.WebCommon\Service
s\SystemHealth\ThrottledSystemHealthChecker.cs:line 67
     at Microsoft.Dynamics.Nav.Client.Web.ThrottledSystemHealthChecker.CheckHealthAndUpdateState(String stateId, Func`1 healthCheck) in s:\repo\src\Platform\Client\We
b\Prod.Client.WebCommon\Services\SystemHealth\ThrottledSystemHealthChecker.cs:line 149

New-BCContainer Telemetry Correlation Id: eef0710b-f300-4635-93b5-d1efb0a63995
Access to the path 'C:\run\Collation.txt' is denied.
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\ContainerHandling\Invoke-ScriptInNavContainer.ps1:112 char:13
+             throw $errorMessage
+             ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Access to the p...txt' is denied.:String) [], RuntimeException
    + FullyQualifiedErrorId : Access to the path 'C:\run\Collation.txt' is denied.

Additional context

freddydk commented 2 years ago

Please try to add -alwaysPull to new-bccontainer to get the latest generic image (just once)

ZacRyon commented 2 years ago

I tried adding it and got the output below. Does it matter where I add it?

cmdlet New-BCContainer -accept_eula -containerName $MyDevContainerName -artifactUrl $MyArtifactUrl -licenseFile $LicenseFile -Auth NavUserPassword -Credential $Credential -updateHosts -isolation hyperv -multitenant -includeAL -UsecleanDatabase -alwayspull -useNewDatabase -assignPremiumPlan -copyTables @('Add-in', 'Report Layout', 'Style Sheet') -myscripts @("https://raw.githubusercontent.com/microsoft/nav-docker/master/override/issue2434/HelperFunctions.ps1")

Output BcContainerHelper is version 3.0.11 BcContainerHelper is running as administrator Hyper-V is Enabled UsePsSession is True Host is Microsoft Windows 10 Pro - 21H1 Docker Client Version is 20.10.14 Docker Server Version is 20.10.14 Removing entries from hosts Removing BC203US from container hosts file Removing BC203US-* from container hosts file Removing Desktop shortcuts Removing C:\ProgramData\BcContainerHelper\Extensions\BC203US Fetching all docker images Fetching all docker volumes INFO: Windows 10 21H1/21H2 images are not yet available, using 2004 as these are found to work better than 20H2 on 21H1/21H2 Pulling image mcr.microsoft.com/businesscentral:10.0.19041.1415 10.0.19041.1415: Pulling from businesscentral Digest: sha256:aa9f9d0779654ab9dba736a43141591a70fa419c4a9a57fd8a517086841280ff Status: Image is up to date for mcr.microsoft.com/businesscentral:10.0.19041.1415 mcr.microsoft.com/businesscentral:10.0.19041.1415 Using image mcr.microsoft.com/businesscentral:10.0.19041.1415 Creating Container BC203US Style: sandbox Multitenant: Yes Version: 20.3.42673.43456 Platform: 20.0.42653.43435 Generic Tag: 1.0.2.10 Container OS Version: 10.0.19041.1415 (2004) Host OS Version: 10.0.19043.1826 (21H1) Using hyperv isolation Using locale en-US Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable) Downloading C:\ProgramData\BcContainerHelper\Extensions\BC203US\my\HelperFunctions.ps1 Using license file C:\OD\OneDrive\Licenses\v20 - expires 30 Aug 2022.flf Files in C:\ProgramData\BcContainerHelper\Extensions\BC203US\my:

ZacRyon commented 2 years ago

Just for the heck of it, I rebooted and tried again. I'm now back at my original error ("Access to path 'C:\run\Collation.txt' is denied").

Here's the output:

BcContainerHelper version 3.0.11 BcContainerHelper emits usage statistics telemetry to Microsoft BcContainerHelper is version 3.0.11 BcContainerHelper is running as administrator Hyper-V is Enabled UsePsSession is True Host is Microsoft Windows 10 Pro - 21H1 Docker Client Version is 20.10.14 Docker Server Version is 20.10.14 Removing entries from hosts Removing BC203US from container hosts file Removing BC203US-* from container hosts file Removing Desktop shortcuts Removing C:\ProgramData\BcContainerHelper\Extensions\BC203US Fetching all docker images Fetching all docker volumes INFO: Windows 10 21H1/21H2 images are not yet available, using 2004 as these are found to work better than 20H2 on 21H1/21H2 Pulling image mcr.microsoft.com/businesscentral:10.0.19041.1415 10.0.19041.1415: Pulling from businesscentral Digest: sha256:aa9f9d0779654ab9dba736a43141591a70fa419c4a9a57fd8a517086841280ff Status: Image is up to date for mcr.microsoft.com/businesscentral:10.0.19041.1415 mcr.microsoft.com/businesscentral:10.0.19041.1415 Using image mcr.microsoft.com/businesscentral:10.0.19041.1415 Creating Container BC203US Style: sandbox Multitenant: Yes Version: 20.3.42673.43456 Platform: 20.0.42653.43435 Generic Tag: 1.0.2.10 Container OS Version: 10.0.19041.1415 (2004) Host OS Version: 10.0.19043.1826 (21H1) Using hyperv isolation Using locale en-US Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable) Downloading C:\ProgramData\BcContainerHelper\Extensions\BC203US\my\HelperFunctions.ps1 Using license file C:\OD\OneDrive\Licenses\v20 - expires 30 Aug 2022.flf Files in C:\ProgramData\BcContainerHelper\Extensions\BC203US\my:

Files: http://BC203US:8080/ALLanguage.vsix

WARNING: You are running a container which is 140 days old. Microsoft recommends that you always run the latest version of our containers.

Container Total Physical Memory is 8.5Gb Container Free Physical Memory is 6.4Gb

Initialization took 52 seconds Ready for connections! Reading CustomSettings.config from BC203US Creating Desktop Shortcuts for BC203US Creating .net Assembly Reference Folder for VS Code Copying DLLs from C:\Windows\assembly to assemblyProbingPath Copying DLLs from C:\Windows\Microsoft.NET\assembly to assemblyProbingPath Copying DLLs from C:\Program Files\Microsoft Dynamics NAV\200\Service to assemblyProbingPath Copying DLLs from C:\Program Files (x86)\Microsoft Dynamics NAV\200\RoleTailored Client to assemblyProbingPath Copying DLLs from C:\Test Assemblies\Mock Assemblies to assemblyProbingPath Copying DLLs from C:\Program Files (x86)\Open XML SDK to assemblyProbingPath Stopping ServiceTier in order to replace database Copying Database on localhost\SQLEXPRESS from CRONUS to mytempdb Taking database CRONUS offline Copying database files Attaching files as new Database mytempdb Putting database CRONUS back online Removing Database CRONUS from localhost\SQLEXPRESS Access to the path 'C:\run\Collation.txt' is denied.

Exception Script Stack Trace: at , : line 36

PowerShell Call Stack: at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 71 at Clean-BcContainerDatabase, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\AppHandling\Clean-BcContainerDatabase.ps1: line 99 at New-BcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\ContainerHandling\New-NavContainer.ps1: line 2237 at , C:\Tools (FAME, BacPac)\BacPac Creation\2. NewSysOnlyContainer.ps1: line 9

Container Free Physical Memory: 7.0Gb

Services in container BC203US:

New-BCContainer Telemetry Correlation Id: 170c0c1b-d073-4102-b49b-bf15dad8a372 Access to the path 'C:\run\Collation.txt' is denied. At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\3.0.11\ContainerHandling\Invoke-ScriptInNavContainer.ps1:112 char:13

ZacRyon commented 2 years ago

Is there any additional info I can provide to help resolve this?

freddydk commented 2 years ago

No, I think the repro scenario is clear - I just need to have time to look at this and I have a few other urgent things after my vacation.

ZacRyon commented 2 years ago

Any progress on this issue? This is holding us up in getting a bunch of clients upgraded to a later version.

freddydk commented 2 years ago

Sorry about the delay, but I have a hard time reproing this, even though the scenario is very clear. I have tried in multiple ways - and even using the same generic image as you - not a problem on my Windows 11, but here's what you should do:

Remove the -myscripts line - the issue2434 fix was only temporary until the generic image was updated

This doesn't fix the problem, but an old override might have other implications, and should not be used here. It also states in comments on issue 2434 that this override is no longer necessary.

Now you can try one out of three things (in order of easiness - any should solve the issue)

  1. Add this to your New-BcContainer: -useGenericImage (Get-BestGenericImageName -hostOsVersion 10.0.17763) which should force your machine to use the latest Windows Server 2019 generic image (instead of the 2004 image) and yes, only specify three elements of the OS version number.
  2. Create a file on your host called collation.txt containing the collation in which you want the database to be created (like collation.txt) and add -myscripts @("your collation file path") to your New-BcContainer statement
  3. Update to WIndows 11 and retry

BTW - you will need (2) if you want to control the collation of your database to be something else than default.

ZacRyon commented 2 years ago

Thank you. I'll try these out.

ZacRyon commented 2 years ago

Thank you for figuring that out. I did the first two suggestions and was able to execute the cmdlet.