In the previous article, Getting started with Visual Studio Code (VS Code), we took a detailed overview of the popular code editor. It supports various programming languages t-SQL, Python, PHP, AWS CLI, PowerShell, etc. We need to use extensions in the VS code to work with these languages. For example, if we open the T-SQL script, it recommends you for the below extension.

We can work on SQL scripts without extension as well, but it does not give added functionality to work on T-SQL. In the below image, we see that you do not get different color codes for the database object. It treats the whole script as a regular file.

Visual Studio Code script

Click on recommendation, and it opens the recommended extension for SQL Server. You can search for a specific extension in the marketplace.

SQL Server extension

Click on Install for SQL Server (mssql) extension. It installs, enables the extension globally along with the SQL tools service for the mssql extension.

Install SQL tools service

Now, let’s add a new connection to SQL Server in VS code. Click on Add Connection.

add a new connection

It opens a prompt to ask for a server name. You can also specify ADO.NET connecting string.

Enter a server name

Press Enter, and you get prompt for a database name. It is an optional field. By default, if we do not enter any database name, VS code connects to the master database.

Enter database name

Next, select the authentication mode from either as SQL Login or Integrated. For a Windows authentication, choose an integrated method. If you choose SQL login, it asks for the credential details of SQL login as well.

authentication mode

Specify a profile name for this connection to SQL Server.

profile name

Press Enter. It connects to SQL Server, and it shows the databases, security, and server objects. You can expand a database to view its objects such as tables, views, functions, stored procedures, etc.

Connect to SQL Server in the VS code

View connection details in User Settings JSON

VS code stores the connection information in a JSON file. To view JSON file content, navigate to File-> Preferences -> Settings.

View connection details in User Settings JSON

In the settings page, click on MSSQL config… from the left-hand menu. It shows the MSSQL:Connections menu.

MSSQL connections

Click on the **Edit in settings.json link. **It opens the mssql connections information that we entered earlier in the VS code.

Edit in settings.json

Suppose you have a lot of connections profiles in your Visual Studio Code. You can copy these connections profile and paste it into the new VS code setting file. It can save our efforts in setting up profiles on new machines or for your colleagues.

Let’s explore a few exciting features of VS code SQL Server extension.

#development #visual studio code

Visual Studio Code (VS Code) for SQL Server development
3.05 GEEK