Registry / database / mssql2

mssql2

JSON →
library3.3.1jsnpmunverified

A fork of node-mssql (v3.3.1) with added dynamic driver option for browserify compatibility. Provides a unified interface for multiple TDS drivers (Tedious, msnodesqlv8, etc.) to connect to Microsoft SQL Server. Includes connection pooling, stored procedures, transactions, prepared statements, bulk load, TVP, and JSON support (SQL Server 2016+). Default driver is Tedious. Primarily used as a drop-in replacement for node-mssql until the patch is upstreamed. Note: This fork may be deleted if the patch is accepted; prefer node-mssql for production.

npm install mssql2
INSTALL
IMPORT
SIG · MSSQL2
M
mssql2
databasejavascriptv3.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import sql from 'mssql2'
const sql = require('mssql2')
Both ESM and CJS work, but default import is recommended.
Request
import { Request } from 'mssql2'
const { Request } = require('mssql2')
Named import also works with CJS destructuring.
ConnectionPool
import { ConnectionPool } from 'mssql2'
const ConnectionPool = require('mssql2').ConnectionPool
ConnectionPool is a named export; avoid default import misuse.
sql.VarChar
import { VarChar } from 'mssql2' or sql.VarChar
Types are accessed via the default import or named imports.

Connects to SQL Server, runs a parameterized query using tagged template literals, and logs the result.

import sql from 'mssql2'; async function run() { try { await sql.connect('mssql://sa:mypassword@localhost/mydb?encrypt=true'); const result = await sql.query`SELECT * FROM users WHERE id = ${1}`; console.log(result.recordset); } catch (err) { console.error(err); } finally { await sql.close(); } } run();
Debug
Known issues
gotchaThis fork may be deleted if the patch is accepted upstream. Prefer node-mssql for long-term stability.
fix
Use the original node-mssql package instead unless you specifically need browserify compatibility.
affects: <4.0
gotchaDynamic driver option added for browserify but not thoroughly tested; may cause unexpected behavior.
fix
Test thoroughly if using in browserify; consider using tedious directly.
affects: >=3.0
breakingVersion 3.x dropped support for callbacks; use Promises or async/await.
fix
Migrate callback patterns to Promises or async/await.
affects: >=3.0 <4.0
gotchaConnection strings with encrypt=true required for Azure SQL.
fix
Append ?encrypt=true to connection string when connecting to Azure.
affects: >=2.0
Errors
Common errors & fixes
TypeError: Cannot read property 'query' of undefined
Forgot to await connect() before executing a query.
fix
Use await sql.connect() before running queries.
Failed to connect to localhost:1433 - connect ECONNREFUSED
SQL Server not running or firewall blocking port 1433.
fix
Ensure SQL Server is running and port 1433 is accessible.
Login failed for user 'sa'
Invalid credentials or SQL Server not in mixed authentication mode.
fix
Check username/password; enable SQL Server authentication.
Request Error: Incorrect syntax near '@P1'
Parameterized query not properly defined (missing input).
fix
Use sql.input() or tagged template literal for parameters.
Upgrade
Version history
3.3.1latest on npm
Audit
Dependencies
tediousrequiredDefault TDS driver for SQL Server connections.
Agent activity
13 hits · last 30 days
node
12
Resources
packagemssql2
mssql2 — npm install mssql2 · libregistry