Page 12 - MSDN Magazine, June 2017
P. 12
Data Points JULIE LERMAN Visual Studio Code: Create a Database IDE
with the MSSQL Extension
While Visual Studio is still my go-to IDE for heavy-duty
.NET development, I’ve fallen head over heels with
Visual Studio Code (VS Code), whether I’m working
in C# or JavaScript or Node and whether I’m working
in Windows or in macOS. Of course, there are many
other languages and frameworks supported by VS Code
and its myriad extensions, but these are my current
toolsets. I’m not alone in my love for VS Code. During the Visual Studio 2017 launch in March 2017, Microsoft announced that VS Code had 1.3 million active monthly users. What’s really great is that, as with any cross-platform tool, each member of your team can pick their favorite OS, yet all can still use the same coding tools.
And then there’s data—there’s always data involved. I spent years and years working only with SQL Server and coding Windows applications. But in the past few years, I’ve expanded my horizons— not only with a new IDE (VS Code), but also new databases and new platforms (as I type this on my MacBook Pro).
My foray into VS Code began as part of my wanderings into Node.js, which you’ve witnessed in this very column. That was originally on Windows. But because VS Code is cross-platform (built with Electron), I eventually found myself going back and forth, working on the same code, sometimes in Windows, sometimes in macOS with GitHub as the common denominator. Thanks to the C# extension and the cross-platform nature of .NET Core, I eventually reached beyond Node.js to write .NET Core apps with EF Core in both environments. When in Visual Studio, I rely heavily on the built-in SQL Server Data Tools and the SQL CE/SQLite Toolbox exten- sion to explore most of the data my apps are creating. But with VS Code, I need something external to explore the data. When using Windows and the super lightweight VS Code, it never felt right to open up SQL Server Management Studio, which is anything but lightweight. For other databases, whether on my Windows or Mac boxes, I’ve also been using JetBrains DataGrip (jetbrains.com/datagrip), a cross-platform database tool that supports a slew of databases.
But as the universe of extensions for VS Code has grown (to just short of 3,000 as I’m writing this in late April 2017), a number of extensions for interacting with data stores have come to the table. Two that I’ve already worked with are the mssql extension (bit.ly/2gb2ICf) from the SQL Server team, and the vscode-database extension for SQLite and PostgreSQL (bit.ly/2mh8nYF). These allow you to write and execute SQL against your databases. You can see demos of both in my Plural- sight course, “Entity Framework Core: Getting Started.” There are other data-related extensions, as well—for example, to interact with Azure
Figure 1 Connecting to a SQL Database with the mssql Extension
Data Lake (also from Microsoft), Redis and SalesForce data. Some of these are still in preview, including the mssql extension.
In this article, I’m going to show you some of the basics of using the mssql extension. Originally I planned to write about both mssql and vscode-database, but mssql is so rich in features, I had a lot of fun exploring it and easily filled up my allotment of words for this column. It makes no difference whether you’re on Windows, macOS or Linux to use mssql.
The mssql extension lets you interact with a variety of SQL Server databases: Microsoft SQL Server, Azure SQL Database and SQL Data Warehouse. As I happen to be sitting in front of a MacBook, I’ll connect to an external SQL Server. You may be aware that SQL Server now runs on Linux—is that not amazing? That means you could spin up a Docker container that runs SQL Server. I won’t do that for this article, but I’ve written a blog post about that, which you can read at bit.ly/2qaev9r. What I will do, however, is connect to an Azure SQL Server database in the cloud. This is a powerful reminder that you don’t need to be a Windows developer or admin or a C# developer to take advantage of SQL Server. You can
Figure 2 TSQL Snippets Provided by the mssql extension
8 msdn magazine