Skip to main content

SQL Server Overview

The SQLSERVER route stores MQTT messages in Microsoft SQL Server databases. It supports Windows and SQL authentication, SSL connections, and enterprise features.
SQL Server is ideal for enterprise environments, especially those integrated with Microsoft ecosystems. It offers advanced features like Always On availability and native JSON support.

Basic Syntax


Connection Configuration

SQL_CONFIG Parameters

SERVER
string
required
SQL Server hostname or IP address. Can include instance name (e.g., server\instance).
DATABASE
string
required
Target database name.
USERNAME
string
required
SQL Server username.
PASSWORD
string
required
SQL Server password.
PORT
integer
SQL Server port. Default: 1433.
USE_SSL
boolean
Enable SSL connection. Default: false.
TRUST_SERVER_CERTIFICATE
boolean
Trust server certificate without validation. Default: false.
Never hardcode credentials in production. Use environment variables and encrypted secrets to keep sensitive values out of your route definitions:
See Environment Variables & Secrets for setup and usage.

Writing Data

Store sensor data in SQL Server:
Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this route. Every PUBLISH MODEL call automatically inserts a row — no query needed:
See Data Storage Overview for the full STORE IN workflow.

Reading Data

EVENTs also support SELECT queries to read data back from the database. Publish a message to the event’s SOURCE_TOPIC, and the query result is published to DESTINATION_TOPIC:
To trigger this query, publish the sensor ID to the source topic:
The query result is published to db/result/latest, where your actions or external clients can consume it.

Timed Polling

EVENTs can also run SELECT queries on a fixed schedule using WITH EVERY:

Table Schema Examples


Troubleshooting

  • Verify SERVER and PORT are correct
  • Check SQL Server is running and accepting TCP connections
  • Enable TCP/IP in SQL Server Configuration Manager
  • Verify firewall allows connections on port 1433
  • Verify USERNAME and PASSWORD are correct
  • Ensure SQL Server authentication is enabled (mixed mode)
  • Check user has permissions on the DATABASE
  • Set TRUST_SERVER_CERTIFICATE “true” for self-signed certs
  • Verify SSL is configured on SQL Server

Next Steps

Data Storage Routes Overview

Compare all storage options.

MongoDB Route

Configure MongoDB document storage.
Last modified on May 22, 2026