A VS Code extension that extends the SQL Server (mssql) extension with quality-of-life features for working with multiple SQL Server environments.
Features
1. Clickable Error Links
When a SQL query fails at runtime, the error is surfaced as a VS Code Diagnostic — a red squiggle on the offending line and a clickable entry in the Problems panel (Ctrl+Shift+M). Clicking the entry jumps directly to the line that caused the error.
A toast notification also appears with a "Go to line" button for quick navigation without opening the Problems panel.
Multiple errors in a single batch are all reported.
2. Automatic Cache Refresh
Before each query run, the extension calls mssql.rebuildIntelliSenseCache to invalidate mssql's cached schema metadata. This ensures that edits to stored procedures, views, and other objects are picked up immediately — no more executing a stale cached version of a procedure you just updated.
3. Server Color Profiles
VS Code's UI colors (status bar, title bar, activity bar, editor tabs) automatically change based on which SQL Server and database you are connected to. Use a red theme for production and a green theme for dev/test — so you always know at a glance which environment you are touching.
Colors update within ~300ms of switching databases via the mssql status bar, or as soon as you interact with the SQL editor. No query needs to be run.
Quick setup
Run the MSSQL Extras: Set Up Color Profiles command (or click the status bar item after connecting) to walk through the setup wizard. The wizard asks for:
- A server name pattern (e.g.
*prod* or *)
- An optional database pattern (e.g.
!*test* — see below)
- A color preset (red / amber / green / blue / dark / light)
- A friendly label shown in the status bar
- Whether to save to User Settings (applies everywhere) or Workspace Settings (shareable via git)
Manual setup
Add a mssqlExtras.serverColorProfiles array to your settings.json. Profiles are evaluated top-to-bottom; the first match wins.
"mssqlExtras.serverColorProfiles": [
{
"serverPattern": "*",
"databasePattern": "*test*",
"preset": "safe",
"name": "Test"
},
{
"serverPattern": "*",
"databasePattern": "!*test*",
"preset": "danger",
"name": "Production"
}
]
In this example:
- Databases whose name contains "test" → green (safe)
- Everything else (prod, staging, master, etc.) → red (danger)
Pattern syntax
| Syntax |
Meaning |
Example |
*prod* |
Contains "prod" (case-insensitive) |
Matches AdvWarehouseProd, PROD-DB |
* |
Matches anything |
Catch-all |
!*test* |
Does not contain "test" |
Matches AdvWarehouseProd, master — not AdvWarehouseTest |
myserver.database.windows.net |
Exact match |
Azure SQL hostname |
? |
Any single character |
server1, serverA |
The ! prefix can be used on both serverPattern and databasePattern.
Verify your patterns
Run MSSQL Extras: Test Server Pattern while connected to see exactly which profiles match your current server/database and which would be applied.
Presets
| Preset |
Color |
Use case |
danger |
🔴 Red |
Production |
warning |
🟡 Amber |
Staging / UAT |
safe |
🟢 Green |
Dev / sandbox / test |
cool |
🔵 Blue |
Reporting / read-only |
dark |
🌑 — |
Switch to Default Dark+ theme |
light |
☀️ — |
Switch to Default Light+ theme |
Usage
Use the MSSQL Extras: Run SQL Query command instead of mssql's built-in run action.
| Action |
Key |
| Run query (with cache refresh + error links) |
Ctrl+Shift+R / Cmd+Shift+R |
To use your existing Ctrl+Shift+E muscle memory, add this to your keybindings.json:
[
{
"key": "ctrl+shift+e",
"command": "mssql-extras.runQuery",
"when": "editorLangId == sql && editorTextFocus"
},
{
"key": "ctrl+shift+e",
"command": "-mssql.runQuery"
}
]
Configuration
| Setting |
Default |
Description |
mssqlExtras.refreshCacheOnRun |
true |
Rebuild the IntelliSense/schema cache before each run |
mssqlExtras.clearPooledConnections |
false |
Also clear pooled connections before each run (stronger, adds a brief reconnect delay) |
mssqlExtras.showErrorsInProblemsPanel |
true |
Surface SQL Server runtime errors as VS Code Diagnostics |
mssqlExtras.enableServerColorProfiles |
true |
Enable automatic color profile switching |
mssqlExtras.serverColorProfiles |
[] |
List of server-to-color mappings. First match wins. |
mssqlExtras.defaultProfile |
null |
Profile applied when no pattern matches. null restores your normal theme. |
Requirements
- The SQL Server (mssql) extension (
ms-mssql.mssql) must be installed and active.
- You must be connected to a SQL Server instance in mssql before running a query.
First-run permission prompt
This extension uses the mssql Connection Sharing API to execute queries on your behalf and capture errors. On first use, mssql will show a one-time permission prompt:
"Allow 'MSSQL Extras' to access your database connection?"
Click Allow. This permission is stored securely and not asked again unless you revoke it.
How It Works
mssql-extras.runQuery
│
├─ 1. mssql.rebuildIntelliSenseCache ← clears schema cache
│
├─ 2. evaluateColorProfile() ← apply colors for active server/DB
│
├─ 3. connectionSharing.executeSimpleQuery() ← runs query, captures errors
│ │
│ ├─ ERROR → parse "Msg N, Line N" →
│ │ create vscode.Diagnostic at that line
│ │ open Problems panel (clickable links)
│ │ (query does NOT run again — no double-execution on errors)
│ │
│ └─ SUCCESS → clear stale diagnostics →
│ call mssql.runQuery to show results grid
Color profile trigger (runs continuously while a SQL file is open)
│
├─ First connect (slow path):
│ connect() → SELECT @@SERVERNAME → cache by connection ID → disconnect()
│
└─ All subsequent checks (fast path, no SQL):
getCachedServerName() + getActiveDatabase() → both in-memory, ~0ms
300ms poll + editor selection events → detect DB switch instantly
Known Limitations
DML double-execution: On the success path, the query runs twice — once for error detection and once via mssql for the results grid. Avoid using this command for INSERT/UPDATE/DELETE statements; use mssql's native run action for those. A future version will detect DML and skip the pre-flight.
Stored procedure line numbers: SQL Server reports error line numbers relative to the start of the CREATE PROCEDURE body, not the .sql file. If you keep each procedure in its own file starting at line 1, the links will be exact.
Multiple result sets: executeSimpleQuery returns only the first result set. Use the mssql results grid (shown automatically on success) to browse all result sets.
Color profile detection latency: Colors update within ~300ms of a database switch as detected by the poller. If the server name hasn't been cached yet (first run on a new connection), a background SQL query fetches it — this takes one round-trip (~50–200ms) and is cached for the rest of the session.
Building
npm install
npm run compile
npm test
To package as a .vsix:
npm install -g @vscode/vsce
vsce package --no-dependencies
code --install-extension mssql-extras-0.1.0.vsix --force
License
MIT