Registry / storage / connect-mssql-v2

connect-mssql-v2

JSON →
library6.0.0jsnpmunverified

Express/Connect session store backed by Microsoft SQL Server, built on the node-mssql driver. Current stable version is 6.0.0, maintained as a revival of the abandoned connect-mssql package. It supports configurable TTL, auto-removal of expired sessions, UTC time handling, connection retries, and emits events for connect, error, and session errors. Distinguished from alternatives by its focus on MSSQL and its compatibility with both CommonJS and ESM via TypeScript declarations.

npm install connect-mssql-v2
INSTALL
IMPORT
SIG · CONNECT-MSSQL-V2
C
connect-mssql-v2
storagejavascriptv6.0.0
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.

MSSQLStore
const MSSQLStore = require('connect-mssql-v2');
import { MSSQLStore } from 'connect-mssql-v2';
Default export only – named import will cause undefined.
MSSQLStore
import MSSQLStore from 'connect-mssql-v2';
import * as MSSQLStore from 'connect-mssql-v2';
ESM default import. TypeScript works with default import.

Creates an Express server with MSSQL session store, incrementing a view counter on each visit.

import express from 'express'; import session from 'express-session'; import MSSQLStore from 'connect-mssql-v2'; const app = express(); const config = { user: process.env.DB_USER ?? 'sa', password: process.env.DB_PASSWORD ?? '', server: process.env.DB_SERVER ?? 'localhost', database: process.env.DB_NAME ?? 'test', options: { encrypt: false, trustServerCertificate: true } }; const store = new MSSQLStore(config, { table: '[sessions]', ttl: 86400000 }); app.use(session({ store, secret: 'mysecret', resave: false, saveUninitialized: false })); app.get('/', (req, res) => { req.session.views = (req.session.views ?? 0) + 1; res.send(`Views: ${req.session.views}`); }); app.listen(3000, () => console.log('Server on 3000'));
Debug
Known issues
breakingv3 changed option names: 'url' is no longer supported. Use 'server' and 'database'.
fix
Provide config object with 'server' and 'database' keys instead of 'url'.
affects: >=3.0.0
gotchaThe session table must be created manually; the store does not auto-create it.
fix
Run the provided CREATE TABLE script before first use.
affects: *
deprecatedThe 'options.url' pattern has been removed. Use config object with explicit properties.
fix
Switch to: new MSSQLStore({ user, password, server, database, options })
affects: >=5.0.0
gotchaDefault export only. Named import (import { MSSQLStore }) returns undefined.
fix
Use default import: import MSSQLStore from 'connect-mssql-v2' or const MSSQLStore = require('connect-mssql-v2').
affects: *
gotchaThe store emits 'sessionError' with error and method name; not all errors are thrown.
fix
Listen for 'sessionError' event to catch internal store errors.
affects: *
Errors
Common errors & fixes
TypeError: MSSQLStore is not a constructor
Using named import instead of default import.
fix
Use const MSSQLStore = require('connect-mssql-v2'); or import MSSQLStore from 'connect-mssql-v2';
Error: ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
SQL Server not running, wrong server/port, or firewall blocking.
fix
Verify SQL Server is running, check config, and ensure TCP/IP is enabled.
Error: Invalid table or object name 'sessions'.
Session table does not exist in the database.
fix
Run CREATE TABLE script provided in the README.
TypeError: Cannot read properties of undefined (reading 'sid')
Session table schema mismatch – missing 'sid' column or wrong column names.
fix
Ensure table has columns: [sid] nvarchar(255) NOT NULL PRIMARY KEY, [session] nvarchar(max), [expires] datetime.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
mssqlrequiredRequired for SQL Server connectivity and queries.
express-sessionrequiredPeer dependency required as the session middleware that this store integrates with.
Agent activity
24 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
connect-mssql-v2 — npm install connect-mssql-v2 · libregistry