Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / SQL Server / Connect to MS SQL Server Database in Visual Studio Code

June 20, 2023 SQL Server

Connect to MS SQL Server Database in Visual Studio Code

To manage databases on Microsoft SQL Server, you can use the lightweight, cross-platform Visual Studio Code editor (VS Code) instead of SQL Server Management Studio (SSMS). Visual Studio Code with the mssql extension allows administrators and developers to manage databases, tables, and stored procedures, as well as run Transact-SQL (T-SQL) queries against on-premises MS SQL Server and Azure SQL databases.

If you already have VSCode installed on your computer, all you need to do is to download and install the mssql extension (https://marketplace.visualstudio.com/items?itemName=ms-mssql.mssql):

  1. Go to Extension (Ctrl+Shift+X) and search for mssql;
  2. Install mssql for Visual Studio Code;
    Install mssql extension for Visual Studio Code
  3. After installation, the SQL Server extension icon will appear in the left panel of the VS Code. Click it (or press Ctrl+Alt+D).
    Connect to Microsoft SQL Server from VScode

Now let’s try connecting remotely from VS Code to a host on which MS SQL Server 2019 is installed:

  1. Click Add Connection and specify the name of the server and the MS SQL instance (hostname\instance_name);
    The Default instance of SQL Server (MSSQLSERVER) listens on a static TCP port 1433. You do not need to specify the connection port when connecting to such an instance. If you have changed the Microsoft SQL Server port, be sure to specify it after the colon: hostname:1430
  2. Select the type of authentication (SQL Login, Integrated, or Azure Active Directory).
    An error may occur when connecting with an MSSQL account:
    mssql: Error 18452: Login failed.
    The login is from an untrusted domain and cannot be used with Integrated authentication.

    mssql: Error 18452: Login failed
    If so, check that SQL Server and Windows Authentication mode is enabled in the Security tab of the MSSQL settings.

    MSSQL Server quthentication mode

  3. Enter your username and password. VSCode will prompt you to save the connection credentials;
  4. Once connected, you will see a list of databases and other objects. You can expand any database and see a list of tables, views, procedures, etc;
    MS SQL Server Database Browser
  5. You can now run various T-SQL queries from the VS Code Editor window. Click the corresponding button in the interface or use the CTRL+SHIFT+E shortcut to run the SQL query. The query results will appear in the next window;
    Run T-SQL query from vscode
  6. You can also export a table with the SQL query results directly from VS Code into a CSV, Excel, or JSON file.

VS Code supports all the IntelliSense features for T-SQL: hints, command autocomplete, color schemes for different objects, etc. Visual Studio Code also supports intelligent SQL code snippets for the quick generation of typical SQL queries.

vscode sql intellisense

The MSSQL connection settings in VSCode are stored in a JSON file. To view its contents, go to File-> Preferences -> Settings -> Extensions -> MSSQL configuration -> Edit in settings.json. The file contains your MSSQL connection details.

MSSQL connection settings in json file

You can also use VSCode instead of PowerShell ISE as your PowerShell script editor. There is also a plugin for VSCode that allows you to remotely connect to a host via SSH.

0 comment
0
Facebook Twitter Google + Pinterest
previous post
How to Downgrade Windows Server Edition or License
next post
How to Get a List of Local Administrators on Computers

Related Reading

Find and Remove Locks in Microsoft SQL Server

March 3, 2023

MS SQL Server Setup Stucks on Install/Uninstall

January 9, 2023

Configure SSL Connection Encryption in MS SQL Server

August 15, 2022

How to Reset SA Password on Microsoft SQL...

December 21, 2021

Upgrade Microsoft SQL Server Evaluation Edition to Standard/Enterprise

December 9, 2021

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Configure SSL Connection Encryption in MS SQL Server
  • Find and Remove Locks in Microsoft SQL Server
  • MS SQL Server Setup Stucks on Install/Uninstall
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top