Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Outline

Connecting JavaScript and Microsoft SQL Server with ADBC

Instructions

Tip

If you already have a SQL Server instance running, skip the steps to run SQL Server in a Docker container.

Prerequisites

  1. Install Node.js (version 22 or later)

    • Alternatively, you can use Bun or Deno
  2. Install dbc

  3. Install Docker

Set up SQL Server

  1. Start SQL Server in a Docker container:

    docker run \
       -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=Co1umn&r" \
       -p 1433:1433 --name mssql --hostname mssql \
       -d \
       mcr.microsoft.com/mssql/server:2025-latest
  2. Create a table in SQL Server and load data into it:

    docker cp games.sql mssql:/tmp/games.sql
    
    docker exec -it mssql /opt/mssql-tools18/bin/sqlcmd \
      -S localhost -U sa -P 'Co1umn&r' -C -i /tmp/games.sql

Connect to SQL Server

  1. Install the SQL Server ADBC driver:

    dbc install mssql
  2. Install dependencies:

    npm --prefix .. install
  3. Customize the script main.js as needed

    • Change the connection arguments in databaseOptions
      • Change uri as needed, using query parameters to add more connection arguments, or keep it as is to use the data included with this example
    • If you changed which database you're connecting to, also change the SQL SELECT statement in conn.query()

Tip

To use Microsoft Entra ID for authentication, install the Azure CLI, log in using the az login command, and add fedauth= to your connection URI. For example:

sqlserver://my-database-endpoint.database.windows.net:1433?database=my-database-name&fedauth=ActiveDirectoryDefault
  1. Run the script:

    Node.js:

    node main.js

    Bun:

    bun run main.js

    Deno:

    deno run --allow-ffi --allow-env main.js

Clean up

Stop the Docker container running SQL Server:

docker stop mssql
docker rm mssql
Morty Proxy This is a proxified and sanitized view of the page, visit original site.