DSN Format
SQL Server connection strings use thesqlserver:// protocol:
Basic Examples
Connection Options
SSL/TLS Modes
SQL Server supports SSL configuration via thesslmode query parameter:
encrypt: false for development convenience. For production, use sslmode=require.
Named Instances
SQL Server supports named instances via theinstanceName parameter:
Timeouts
Configure connection and query timeouts via TOML:mssql library (src/connectors/sqlserver/index.ts:84-89).
NTLM Authentication
For Windows domain authentication, use NTLM:authentication=ntlmparameterdomainparameter specifying Windows domain- Domain username and password
- NTLM requires
domainparameter (error if missing) domainparameter requiresauthentication=ntlm(error if inconsistent)
Azure Active Directory Authentication
For Azure SQL Database, use Azure AD authentication:DefaultAzureCredential to automatically obtain access tokens from:
- Environment variables
- Managed Identity (in Azure)
- Azure CLI credentials
- Visual Studio credentials
- Azure PowerShell credentials
Supported Features
Schemas
SQL Server has full schema support. List all schemas:dbo
Tables and Views
Get tables in a schema:Table Schema with Comments
SQL Server supports column descriptions via extended properties:Indexes
SQL Server indexes include:- Primary keys (
is_primary: true) - Unique indexes (
is_unique: true) - Multi-column indexes
- Clustered and non-clustered indexes
- Filtered indexes
Stored Procedures and Functions
SQL Server supports both stored procedures and functions:sys.sql_modules.
Table Comments
Retrieve table-level descriptions:Query Execution
Parameterized Queries
SQL Server uses@p1, @p2, etc. for parameters:
string→VarCharnumber(integer) →Intnumber(float) →Floatboolean→Bitnull/undefined→VarCharArray/Object→VarChar(JSON stringified)
Row Limiting
SQL Server usesTOP or OFFSET-FETCH for limiting results:
Multi-Statement Support
SQL Server supports multi-statement execution:Common Scenarios
Connect to Local SQL Server
Connect to Azure SQL Database
Option 1: SQL AuthenticationAZURE_TENANT_ID,AZURE_CLIENT_ID,AZURE_CLIENT_SECRETenvironment variables- Managed Identity (when running in Azure)
- Azure CLI (
az login)
Connect with Windows Authentication (NTLM)
Connect Through SSH Tunnel
Use Multiple Schemas
SQL Server-Specific SQL Examples
JSON Queries (SQL Server 2016+)
Window Functions
CTEs with MERGE
Temporal Tables (SQL Server 2016+)
Full-Text Search
Troubleshooting
Connection Refused
Error:connect ECONNREFUSED
Solutions:
- Verify SQL Server is running:
services.msc→ SQL Server service - Check SQL Server Configuration Manager:
- Enable TCP/IP protocol
- Set TCP port to 1433
- Verify Windows Firewall allows port 1433
- For named instances, ensure SQL Server Browser service is running
Login Failed
Error:Login failed for user 'username'
Solutions:
- Verify SQL Server authentication mode (mixed mode required for SQL auth)
- Check user exists:
- Grant login access:
Named Instance Not Found
Error:Failed to connect to named instance
Solutions:
- Verify instance name:
SELECT @@SERVERNAME - Ensure SQL Server Browser service is running
- Use correct DSN format:
Certificate Validation Failed
Error:The certificate chain was issued by an authority that is not trusted
Solutions:
- Use
sslmode=requireto skip certificate verification: - Or disable encryption for development:
Azure AD Authentication Failed
Error:Failed to get Azure AD token
Solutions:
- Configure Azure credentials:
- Or authenticate with Azure CLI:
- Verify user has access to Azure SQL Database
NTLM Authentication Failed
Error:NTLM authentication failed
Solutions:
- Verify domain parameter matches Windows domain
- Use domain\username format correctly
- Check DSN format:
Performance Tips
- Use connection pooling (enabled by default in connector)
- Create appropriate indexes for frequently queried columns
- Use parameterized queries to enable query plan caching
- Use SET NOCOUNT ON in stored procedures to reduce network traffic
- Consider columnstore indexes for analytics queries
- Use filtered indexes for queries with common WHERE conditions
- Monitor query execution plans with EXPLAIN or SQL Server Profiler
- Use table partitioning for very large tables