Note

this article assumes you have a problem with installing msodbc.msi, but the same principles MIGHT apply to any other package which is available in chocolatey.

based on this link from Microsoft (please MS, ffs stop changing and invalidating your links!) a simple

msiexec /quiet /passive /qn /i msodbcsql.msi IACCEPTMSODBCSQLLICENSETERMS=YES ADDLOCAL=ALL

would be enough to install the package on any machine from command line or powershell; but haha! that would be sooo easy, wouldn’t it!

to check if a package is installed on docker using powershell, you can use

WMIC SOFTWAREFEATURE LIST BRIEF

to see a list of all the installed packages. if your installation has gone according to your plan, then you’ll be able to see something like this:

installed packages on a docker machine

you are not seeing your ODBC driver (or your package) in the list, then you are screwed, again! so what shall we do? okay, follow me:

  1. ogo to chocolatey package search and search for your package. if you find it on the list, you are in luck, otherwise, please google for other solutions! if you found your package in chocolatey, in my case msodbc then go forward:
  2. install chocolatey on your docker. I used the following command in powershell:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

  1. now you have `choco` on your system! try `choco -?` to check if it’s working. is it? wonderful, continue!
  2. okay, now checkout the version of msodbc you want to install. if it already exists on the choco repository, the chances are you can install them just by using

choco install sqlserver-odbcdriver --version [your-version-here]

  1. now comes the “tricky” part: as I tried to use choco install sqlserver-odbcdriver --version 12.0.4219.0to install an older version of the driver, I was informed that the link to microsoft’s website containing the actual package is not available anymore! Thanks microsoft for constantly changing the links!
    so how do you get past this issue? on the sidebar of the chocolatey page, there is a download button which allows you to download a .nupkg file containing installation instructions for chocolatey. you can always install a choco-package using this file. the trick is to modify this file in a way that it points to correct paths. to do so, follow these instructions:
    1. open the .nupkg with a zip-archiver. the file is nothing other that a renamed .zip. you will have something like this:
the structure of the .nupkgfile
    1. go to tools, open chocolateyinstall.ps1 with a text editor. the contents will look something like this:
$packageName = 'sqlserver-odbcdriver'
$installerType = 'msi'
$silentArgs= '/Passive /NoRestart IACCEPTMSODBCSQLLICENSETERMS=YES'
$url = 'https://download.microsoft.com/download/5/7/2/57249A3A-19D6-4901-ACCE-80924ABEB267/1033/x86/msodbcsql.msi'
$url64 = 'https://download.microsoft.com/download/5/7/2/57249A3A-19D6-4901-ACCE-80924ABEB267/1033/amd64/msodbcsql.msi'
$checksumType = 'sha256'
$checksum = 'CE9B9DDD8F38926DF374C1B947DD8A312495E8D81BE985109347E432257BA53E'
$checksum64 = 'CC7FD7CBB9840DE239DCC0C8AB12D2CC2BCF411AF4B0B8BD5AB0730805F2F4B3'
Install-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" "$url64" -validExitCodes @(0) "$checksum" "$checksumType" "$checksum64" "$checksumType"
    1. Microsoft has changed the links mentioned in $url and $url64. you have to find the correct paths. one way is to visit microsoft’s ODBC Driver Download page, follow the links to your desired package and then check your browser’s download history for the correct link. it turns out, they have replaced the 1033/amd64 and 1033/x86 with /ENU/x64 and /ENU/x86 respectively.
    2. make sure that the checksum values are also correct.
    3. now save the file, and compress the package-files back into a .zip file and rename the extension to .nupkg.
    4. you can now use choco install sqlserver-odbcdriver.12.0.4219.0.nupkg (or whatever your package is called) to install this MSI on the system.

I’m not a chocolatey expert, but I believe you can always create your own packages by creating a similar structure (maybe only the tools > chocolateyinstall.ps1 and package.nuspec files are needed to create a proper package?) and ask choco to install them for you.

hope this has helped you! 🙂 go have fun now 😉

Comments are closed, but trackbacks and pingbacks are open.