Skip to main content

SQL Server Overview

The SQLSERVER connector 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

string
required
SQL Server hostname or IP address. Can include instance name (e.g., server\instance).
string
required
Target database name.
string
required
SQL Server username.
string
required
SQL Server password.
integer
SQL Server port. Default: 1433.
boolean
Enable SSL connection. Default: false.
boolean
Trust server certificate without validation. Default: false.
integer
Maximum connections in the pool. Passed to the SQL Server driver. Omit to keep the driver default.
integer
Minimum connections in the pool. Passed to the SQL Server driver. Omit to keep the driver default. Must be less than or equal to MAX_POOL_SIZE.
integer
How long an idle pooled connection may be kept. Passed to the SQL Server driver. Omit to keep the driver default.
integer
How long a pooled connection may be kept. Passed to the SQL Server driver. Omit to keep the driver default.
integer
How many MQTT-triggered SQL events may run at once. Alias: MAX_CONCURRENT_WRITES. Optional.
string
default:"block"
What to do when MQTT-triggered writes are already at WRITE_CONCURRENCY. block waits, and WRITE_QUEUE_CAPACITY is ignored. drop_oldest and drop_newest apply WRITE_QUEUE_CAPACITY. Dropping an event logs a Warning and counts the drop.
integer
How many waiting MQTT-triggered events to keep when the policy is drop_oldest or drop_newest. Ignored when the policy is block.
Invalid pool values are refused. MIN_POOL_SIZE must be less than or equal to MAX_POOL_SIZE. A failed query does not mark the connector Disconnected. A constraint violation, a cast error, a command timeout (-2), cannot-open-database (4060), an exhausted pool, and any other query failure leave it connected. Only a transport or connection failure marks it Disconnected, so one bad row does not stop later telemetry.
Never hardcode credentials in production. Use environment variables and encrypted secrets to keep sensitive values out of your connector definitions:
See Environment Variables & Secrets for setup and usage.

Reconnecting after a dropped connection

When the database ends the connector’s sessions or the connection drops, the connector is marked Disconnected. The next event reconnects it, straight away and then at most every 5 seconds until the database answers, and runs once the connection is back. No redeploy is needed. The event that was running on the dropped session fails and is not retried.

Agent queries

An agent can read this database when the connector opts in and the agent grants connector_query. The agent runs one read statement. It cannot insert, update, or delete. See Database queries. SQL Server is refused unless you set AGENT_USERNAME and AGENT_PASSWORD, or AGENT_CONNECTION_STRING. It does not fall back to a read-only transaction on the connector login. The person who asks and the agent’s DEFAULT_USER both need PublishSys on $SYS/Coreflux/Routes/<connector>/Query.

How placeholders are quoted

The broker places each placeholder in an event QUERY by the quotes around it. A publisher on the source topic can no longer change the SQL by putting SQL in the payload.
Action: Put every placeholder that carries text in single quotes (WHERE status = '{payload}'). Put a placeholder that names a table or column in double quotes (FROM "{topic.2}") or brackets (FROM [{topic.2}]). An unquoted placeholder must be a number, a comma-separated list of numbers, true, false, or null. Anything else, including a bare name such as line_1, refuses the event. The message names the placeholder.
{env.NAME} and {secret.NAME} are placed as written. A value that itself contains {topic} is stored as text and is not expanded again. The same rules on the other SQL engines are in How placeholders are quoted. MongoDB and OpenSearch JSON queries place each value as one JSON value instead (see OpenSearch placeholders).

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 connector. 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
The broker runs without the ICU library, which SQL Server connections need. This happens on broker 2.22 and earlier, or when DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 is set.
  • Upgrade the broker
  • Remove DOTNET_SYSTEM_GLOBALIZATION_INVARIANT from the broker’s environment
  • On a portable Linux binary, install libicu on the host. See Installation

Next Steps

Data Storage Connectors Overview

Compare all storage options.

MongoDB Connector

Configure MongoDB document storage.
Last modified on December 4, 2026