SQL Server

Detailed information on the SQL Server state store component

Create an Azure SQL instance

Follow the instructions from the Azure documentation on how to create a SQL database. The database must be created before Dapr consumes it.

Note: SQL Server state store also supports SQL Server running on VMs.

In order to setup SQL Server as a state store, you will need the following properties:

  • Connection String: the SQL Server connection string. For example: server=localhost;user id=sa;password=your-password;port=1433;database=mydatabase;
  • Schema: The database schema do use (default=dbo). Will be created if not exists
  • Table Name: The database table name. Will be created if not exists
  • Indexed Properties: Optional properties from json data which will be indexed and persisted as individual column

Create a dedicated user

When connecting with a dedicated user (not sa), these authorizations are required for the user - even when the user is owner of the desired database schema:

  • CREATE TABLE
  • CREATE TYPE

Create a Dapr component

Currently this component does not support state management for actors

The next step is to create a Dapr component for SQL Server.

Create the following YAML file named sqlserver.yaml:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: <NAME>
  namespace: <NAMESPACE>
spec:
  type: state.sqlserver
  metadata:
  - name: connectionString
    value: <REPLACE-WITH-CONNECTION-STRING>
  - name: tableName
    value: <REPLACE-WITH-TABLE-NAME>

Example

The following example uses the Kubernetes secret store to retrieve the secrets:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: <NAME>
  namespace: <NAMESPACE>
spec:
  type: state.sqlserver
  metadata:
  - name: connectionString
    secretKeyRef:
      name: <KUBERNETES-SECRET-NAME>
      key: <KUBERNETES-SECRET-KEY>
  - name: tableName
    value: <REPLACE-WITH-TABLE-NAME>

Apply the configuration

In Kubernetes

To apply the SQL Server state store to Kubernetes, use the kubectl CLI:

kubectl apply -f sqlserver.yaml

Running locally

To run locally, create a components dir containing the YAML file and provide the path to the dapr run command with the flag --components-path.