Connecting to SQL Server from VS Code

I am not sure if you have used VS Code but it has quickly become my favorite editor. Being cross platform is a huge draw for me since I can utilize it on my macbook and my windows desktop.

It has a lot of utility for multiple languages, for example I have been diving into dotnet core and I can use it to develop MVC sites directly on my macbook using the same editor as I would on my desktop.

If there is one thing I am missing in my OSX life, it's a decent SQL Server tool. Sure there are plenty of them out there that do some things. However the UI generally leaves multiple things to be desired and I really just want to be able to run some queries.

Enter VS Code.

You will need a few things to start.

First we will want to install the MSSQL Extension. When you open VS Code, on the left hand side you will see five tabs in a vertical column. If you hover over each one of them it will tell you what they are:

When you click on the extension tab, you will have the option to search for the MSSQL Extension. Go ahead and install it. It will ask you to reload, go ahead.

Next we need to create a .SQL file, I named mine DatabaseTest.sql, doesn't particularly matter what you name yours so long as VS Code can see it's a sql file.

Next we need to create a connection profile for VS Code to use to connect with, to do that we need to open the Command Pallete.

Next type sqlcon to get the profile manager open.

I already have one made, but you will want to select Create Connection Profile. This will walk you through a general connection string creation, you can choose to save it or not.

Once this is done it will attempt to connect, you can see down at the bottom bar if it has or not.

After this, you will want to run a query to test it out.

And if the query runs succesfully, a results tab will open for you!

Bonus:

If you want to have Horizontal splits: