Database User Resource
Synopsis
Manages SQL Server database users, including SQL users mapped to logins, Windows users, contained database users, and certificate or asymmetric key mapped users.
Type
Capabilities
- Get
- Set
- Delete
- Export
Properties
serverInstance
SQL Server instance name.
connectUsername
Username for SQL authentication.
connectPassword
Password for SQL authentication.
databaseName
Name of the database containing the user.
name
Name of the database user.
userType
User type. See User types below.
login
Login mapped to this user. Required for SqlUser.
defaultSchema
Default schema for the user.
password
Password for contained database users.
asymmetricKey
Asymmetric key name. Used for AsymmetricKeyMappedUser.
certificate
Certificate name. Used for CertificateMappedUser.
defaultLanguage
Default language.
createDate
Creation date.
dateLastModified
Date last modified.
hasDBAccess
Whether the user has database access.
isSystemObject
Whether this is a system user.
sid
Security identifier (SID).
authenticationType
Authentication type.
_exist
Whether the user should exist.
User types
| Value | Description |
|---|---|
SqlUser |
SQL user mapped to a server login |
NoLogin |
User without a login |
WindowsUser |
Windows user |
WindowsGroup |
Windows group |
CertificateMappedUser |
User mapped to a certificate |
AsymmetricKeyMappedUser |
User mapped to an asymmetric key |
ExternalUser |
External user (Microsoft Entra ID) |
ExternalGroup |
External group (Microsoft Entra ID) |
Examples
Example 1 — Get a database user
Example 2 — Create a user mapped to a login
Example 3 — Configuration document
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
resources:
- name: Application database user
type: OpenDsc.SqlServer/DatabaseUser
properties:
serverInstance: "."
databaseName: AppDb
name: AppUser
userType: SqlUser
login: AppUser
defaultSchema: dbo
Exit codes
| Code | Description |
|---|---|
| 0 | Success |
| 1 | Error |
| 2 | Invalid JSON |
| 3 | Invalid argument |
| 4 | Unauthorized access |
| 5 | Invalid operation |