Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

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

March 15, 2024 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 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. Specify the SQL Server name and connection port: 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
2
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

Upgrade Microsoft SQL Server Evaluation Edition to Standard/Enterprise

December 9, 2021

Configuring Always-On High Availability Groups on SQL Server

December 2, 2021

SQL Server: Could Not Find the Database Engine...

September 30, 2019

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

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

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

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

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


Back To Top