SQL Server Driver Adapter
The@prisma/adapter-mssql package enables usage of the mssql driver for Microsoft SQL Server and Azure SQL Database with Prisma ORM.
Installation
Usage
Configuration Object
JDBC Connection String
You can also use a JDBC-style connection string:Configuration Options
The adapter accepts configuration from the Tedious driver:Entra ID Authentication (Azure Active Directory)
The adapter supports various Entra ID authentication methods:DefaultAzureCredential
Use Azure’s DefaultAzureCredential for flexible authentication:Username/Password (Active Directory)
Managed Identity
Service Principal
Transaction Support
The adapter supports all transaction features:Isolation Levels
SQL Server supports all standard isolation levels plusSNAPSHOT:
SNAPSHOT isolation requires enabling it on the database:
Savepoints
The adapter supports nested transactions using SQL Server’s savepoint syntax:SAVE TRANSACTION and ROLLBACK TRANSACTION for savepoints, and does not support RELEASE SAVEPOINT.
Error Handling
The adapter maps SQL Server errors to Prisma error codes:| SQL Server Error | Prisma Code | Description |
|---|---|---|
| 2627, 2601 | P2002 | Unique constraint violation |
| 547 | P2003 | Foreign key constraint violation |
| 515 | P2011 | Null constraint violation |
| 8152 | P2000 | Value too long for column |
| 18456 | P1000 | Authentication failed |
| -1 | P1001 | Can’t reach database server |
Azure SQL Database
Connection example for Azure SQL Database:Connection String Format
JDBC-style connection string syntax:Features
- Full transaction support with all isolation levels including
SNAPSHOT - Savepoint support for nested transactions
- Connection pooling
- Entra ID (Azure AD) authentication
- Windows Authentication
- Azure SQL Database support
- TLS/SSL encryption
Limitations
- The adapter requires the
mssqlnpm package version 12.2.0 or later - SQL Server does not support
RELEASE SAVEPOINT(savepoints are automatically released)