HOW TO Refresh NAV database in NAV Container without the need to Recreate the container

This post actually started with an Issue I created in NavContainerHelper GitHub.

💡 I’m working in a script for Continuous Integration and although the creation of a container requires few minutes I was looking how to optimize the time of execution of the whole build process.

Freddy Kristiansen is a Microsoft Evangelist that is working hard to make it easier to work with NAV using Docker Containers, thanks again Freddy.

Freddy initially marked my issue with label “WONTFIX” 🙁 but after I explained to him my motivation he changed the label to “ENHANCEMENT” 😀

He did not include any new functionality to NavContainerHelper but he kindly provided me with the script to copy and paste, and as I always do, I like to share good things.

Solution:
Right after the creation of a NAV Container, run the following script:

# To add just after the creation of the NAV Container
$containerName = "scadev"
$config = Get-NavContainerServerConfiguration -ContainerName $containerName
Invoke-ScriptInNavContainer -containerName $containerName -scriptblock { 
  Param($DatabaseServer, $DatabaseInstance, $DatabaseName, $NewDatabaseName)
    Copy-navDatabase -DatabaseServer $DatabaseServer -DatabaseInstance 
  $DatabaseInstance -SourceDatabaseName $DatabaseName -DestinationDatabaseName 
  $NewDatabaseName
} -argumentList $config.DatabaseServer, $config.DatabaseInstance, $config.DatabaseName, "backup"

So next time you run the build process, just verify that the Container exists and in case replace the database with the backup taken previously (it takes 10-20 seconds)

$containerName = "scadev"
if (Test-NavContainer $containerName) {
  $config = Get-NavContainerServerConfiguration -ContainerName $containerName
  Invoke-ScriptInNavContainer -containerName $containerName -scriptblock { 
    Param($DatabaseServer, $DatabaseInstance, $DatabaseName, $NewDatabaseName)
    Copy-navDatabase -DatabaseServer $DatabaseServer -DatabaseInstance 
    $DatabaseInstance -SourceDatabaseName $DatabaseName -DestinationDatabaseName 
    $NewDatabaseName
  } -argumentList $config.DatabaseServer, $config.DatabaseInstance, "backup", $config.DatabaseName
} else {
# Creation of NAV Container
}

Source: https://github.com/Microsoft/navcontainerhelper/issues/315

Did my HOW TO help you? Leave a reply.

HOW TO change version from Visual Studio 2015 Enterprise to Professional

You must uninstall the installed version to install the new one. The two version cannot be installed in the same machine, when you run the Installation of Visual Studio 2015 Professional the installation stops because another version is already installed.

I suggest you, before to uninstall, to navigate to the Windows Control Panel to modify existing installation so that you can take note of the components/features installed.

Did my HOW TO help you? Leave a reply.