Microsoft SQL Server on a Ubuntu Linux VM

Apr 15 17

As part of a blog post on the LEDS stack (Linux Nginx Dotnet, SQL Server) I’m putting together, I wanted to see how easy it is to install SQL Server on a Ubuntu VM, running on Digital Ocean.
Turns out, very easy.

I went with a Ubuntu  16.04.2 x64 box, with 4GB of RAM
The docs state that you need at least 3.25GB of memory to run SQL Server on Linux.

digital_ocean_ubuntudigital_ocean_4gb_ram

Once my droplet had created, I SSH’d into it.

First, we need to import the public repository GPG keys, and register the Microsoft SQL Server Ubuntu repository

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list

Then, it’s a simple

sudo apt-get update
sudo apt-get install -y mssql-server

And SQL Server is installed in around 2-4 minutes.

Next up, it tells you the command you’ll need to run:

sql_linux_complete_setup

Which is

sudo/opt/mssql/bin/mssql-conf setup

for those copying and pasting.

Once you’ve accepted the license terms (you do accept them, don’t you?) and chosen a secure SA password, setup is complete.

You can verify the service is running with:

systemctl status mssql-server

ms_sql_linux_service_running

Back in Windows…
To test out your new SQL Server install on Linux, you can connect to it using SSMS (Windows)
I’m currently using SQL Server Management Studio – Release Candidate (17.0 RC3)
(I tested it with 2014, and it worked fine.)

Note:
Port 1433 was open on my VM, but it may be blocked with your firewall!

Restoring the Northwind database backup.

Ok, next let’s get a database up and running on our Linux SQL Server.
I downloaded the Northwind database backup to my local machine.

I used SCP to copy the backup of the Northwind database:

scp Northwind.bak.zip root@:/var/opt/mssql

This copies my Northwind.bak.zip file into /var/opt/mssql on the remote server.

I’m using a mac, so SCP is installed already.
If you’re on Windows, you’ll need to use something like WinSCP

Since I uploaded a zipped backup file, I’ll need to unzip it.

If the unzip command isn’t already installed on your system, then run:

sudo apt-get install unzip

Then it’s just a simple

unzip Northwind.bak.zip

Next, with SSMS locate the backup file, and restore in the usual way:

ms_sql_linux_service_restore_bak

Note: SSM puts “C:\” in front of your path in the location bar
This can be ignored, but for some reason it does need to be there.

And there we have it. The Northwind database, restored on to a SQL Server instance, running on Linux, on a non-Microsoft cloud.

ms_sql_linux_northwind_restored

Using different themes across Visual Studio versions

Apr 12 17

I’m currently working on a couple of solutions – one that is Visual Studio 2017 specific, one 2015.
Primarily because the 2017 specific one is full of .net standard projects, and the support is better (or at least, built in)

I wanted to have 2015 use a different theme – I’m only doing small bits in it, but have them both open at the same time, so figured having one light, and one dark (my preferred) would make distinguishing them a lot easier on my multi-monitor setup.

I changed the theme to ‘light’ in Visual Studio 2015. Thought that was that, but almost immediately, 2017 changed to the light them too.
So I changed 2017 back to dark, and you guessed it, the lights went out on 2015.

Turns out that settings are synchronised using your signed in Visual Studio account.
Being signed in as the same user on both editions of Visual Studio was syncing my settings – in real time. Which most of the time would be exactly what I want, however on this occasion, I need to turn it off.

Luckily, there’s a setting for that:

vs_sync_settings

Un-ticking this check-box allows me to have one running in light, one running in dark.
This does of course stop all settings synchronising, so I’m only using it temporarily.

Lack of Godaddy email support prompts me to move

Apr 5 17

I’ve been a customer of GoDaddy for several years.
Recently, I’ve required to use their support service.
Unusually, they don’t offer email support – just phone, or live-chat

On more than one occasion, live-chat has been unavailable, and making a call hasn’t been convenient.
Secondly, live-chat only works with a persistent connection. Working on a train, for example, means you’ll often be cut off from the live-chat service mid-support session.

This is one reason I’ve been moving most of our domains over to Namecheap.
Their support team is always on hand, both chat and email (I much prefer email where possible)
I realise this is personal preference, but having email support much more suits the way I work – not necessarily always connected!

Clearing Chrome Internal DNS cache

Nov 24 16

Visiting a url, but getting the (old dns) version of a page?
I was too.

Turns out that Chrome keeps an internal DNS cache.

You can view it by visiting the following ‘url’ (enter this in your address bar in Chrome)

chrome://net-internals/#dns

Out Of Memory exception when deserializing with JSON.net – Use Streams instead

Nov 1 16

Calling an api and deserializing the returned json into a type is something I have to do quite often.

I used to use the following:


If the JSON returned is large, we’ll often get an Out Of Memory Exception

From the docs

To minimize memory usage and the number of objects allocated, Json.NET supports serializing and deserializing directly to a stream.

To rectify this, we can instead use Streams

 

In my example, where the JSON has a nested ‘result’ element, you’ll also need a class to represent this (see TypeContainingMyResult above)