Execute Azure SQL Server Queries directly within Visual Studio Code

mbue nx
mbue nx
Aug 29, 2017 · 2 min read

I have been searching for an SQL Server database viewer which can be used on Mac OS X to execute some queries against Azure SQL Databases. All the tools I tried felt rather bloated or did not work. Finally, I came across a really nice Visual Studio Code extension called *mssql*. It allows you to execute arbitrary T-SQL statements directly from the VS Code editor.

The setup is straightforward:

  • Download the extension “mssql” from the Marketplace (View/Extensions menu or Command-Shift-X on Mac)
  • If you are using Mac OS X, you have to install OpenSSL. You can do this by using brew on the command line:
brew update brew install openssl ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/ ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
  • Now we will configure the Azure SQL Database connection.
    Hit F1 and type “User Settings” (or Command-, on Mac) which opens the settings.json configuration. Find the _mssql.connections_ array and add your Azure SQL database by specifying a connection object:
“mssql.connections”: [  {    “server”: “your.azure.database.url.windows.net”,    “database”: “your_database”,    “user”: “your_user”,    “password”: “”  }]
  • Add a new .SQL file to your project and type a query, e.g.
SELECT * FROM MyTable
  • Right click and choose execute query (or hit Shift-Command-E on Mac):

Visual Studio Code will prompt for the connection you want to use.
Choose the connection we created within settings.json and your query result set is already shown.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade