Connect Local SQL to NAV Container

Connect Local SQL to NAV Container

Have you ever wanted to be able to use the easy setup of navcontainerhelper to setup your infrastructure but you would like to be able to connect to a “real” database to your Docker? Well look no further, in this post I will show you how you can accomplish just this. Now just a disclaimer, this is nothing new that I have come up with, there a lot of blog posts out there that shows you how to achieve just this, but hopefully this post will show you the easiest way for you to get from point A to B. 

But why would you want to connect a Docker to a local database? Well there can be many reasons for this, one could be that you would like some real data to test your extensions on and another, which I feel is the most used reason is during upgrades, because it will save you a lot of time, not having to setup all your infrastructure when upgrading. Now some of you might be tempted to think hmm.. well if I can connect my database to a Docker, then why not run all my production infrastructure on a Docker, and while this would be possible. Microsoft does not “yet” support this, so I would recommend that you wait, until Microsoft says that it is supported.  

Well let us get started, the first thing you have to do is make sure that your SQL Server is running in mixed mode, this is done by opening your SQL Studio Management going to server properties -> security and choose SQL Server and Windows Authentication mode. 

No alt text provided for this image

This will allow you to connect to the SQL using both Windows and SQL user logins. Next you need to go to connections and make sure that you allow remote connections. 

No alt text provided for this image

Next you need to create a new SQL Login by going to logins and creating a new user and choose SQL Server Authentication, and make the user Sys admin. 

No alt text provided for this image
No alt text provided for this image

You should also open port 1433 in your firewall for inbound traffic. 

When all this is setup you are ready to create your new container and that is done with the following PowerShell script. 

$credential = Get-Credential
$dbcredentials = Get-Credential
$imageName = 'mcr.microsoft.com/businesscentral/onprem:14.7.37609.0-dk-ltsc2019'
$containerName = 'MyTest'
$DatabaseName = 'MYBC14'
$License = 'C:\License\MyLicense.flf'


New-BCContainer `
    -accept_eula `
    -containerName $containerName `
    -imageName $imageName `
    -updateHosts `
    -auth UserPassword `
    -Credential $credential `
    -databaseServer '10.100.12.39' `
    -databaseInstance '' `
    -databaseName $DatabaseName `
    -databaseCredential $dbcredentials `
    -licenseFile $License `
    -includeAL 
New-NavContainerNavUser -containerName $containerName -Credential $credential -ChangePasswordAtNextLogOn:$false -PermissionSetId SUPER

Where you must change the -databaseServer '10.100.12.39' to your own local IP, and that is it this will create a new NAV container running on a local SQL database, enjoy 😊 

OBS:

My kollega Thomas Guldstrand made me aware that I missed a step which is to

Remember to enable TCP/IP in the SQL network configuration.

Der er ingen alternativ tekst for dette billede


Hi Dennis, I have restored my SAAS DB to my local SQL server and tried to connect the connector to it, however, it's showing the following error, I couldn't find shown table in the DB. how can get over this problem?

  • No alternative text description for this image
Like
Reply

I like it. But since you already use Docker, why not connect to a SQL Server running in a Docker container as well? Data and log files could still reside locally.

To view or add a comment, sign in

More articles by Dennis Fredborg

  • Becoming a programmer

    So you want to know what it takes to become a programmer? Well that is what we will cover in this post, first off it is…

  • Testing Performance Business Central

    There are a couple of ways of testing performance in Business Central, you of cause have the manual testing where you…

  • Background Sessions In Business Central

    In the last post and video, I talked about Page Background Tasks and how you could use these tasks to increase…

    1 Comment
  • Page Background Task in Business Central

    This post is a supplement to my video from last week, so if you watched my video, you won't find much new in this post,…

  • Migrate to Business Central Cloud

    I just recently upgraded my first customer from an on prem installation to the Business Central cloud, and what a ride…

    6 Comments
  • Simple Build Pipeline for Business Central

    To be honest this is one of those blog posts that I have been having an inner struggle about rather or not to write…

  • NAV Tech Days 2019 Day 2

    I finally got the time to write my key takeaways from day two of NAV Tech Days 2019. Build, test, deploy and deliver…

    1 Comment
  • NAV Tech Days 2019 Day 1

    One again I have had the privilege, to be allowed by my company, to attend NAV Tech Days. 😊 So in this post, I will…

    4 Comments
  • Printing in Business Central

    Printing is, in my opinion, one of the most lacking features in Business Central, because while you can print using the…

    3 Comments
  • Extension Code Signing

    In this post we will take a look at code signing, this post is going to be very short since there really is not much to…

    2 Comments

Others also viewed

Explore content categories