Logging MODBUS RTU to MS SQL Database In Real-Time
A complete guide to polling MODBUS RTU serial devices and exporting the register data directly into a MsSQL database with your database structure.
1. Protocol Configuration: MODBUS RTU
Communication Type: Active Polling (Master/Slave over RS485/COM)
Because MODBUS transmits data in binary, the parser must extract specific Holding Registers (e.g., 40001) or Input Registers. If your sensor uses 32-bit floating-point numbers, configure the parser to read two adjacent 16-bit registers and apply the correct byte-swapping (endianness) to reconstruct the float.
Apply this base configuration for the serial connection:
{
"port": "COM3",
"baud_rate": 9600,
"data_bits": 8,
"stop_bits": 1,
"parity": "none",
"protocol": "modbus_rtu_serial",
"poll_interval_ms": 1000
}
MODBUS RTU plugin selection to query and parse data.

MODBUS RTU query queue: custom configuration to read different registers.
Ready to connect MODBUS RTU to Microsoft SQL Server?
2. Database Setup: Microsoft SQL Server
Use the built-in SQL Server Native Client or OLE DB provider within the Data Logger's ODBC export module. Windows Authentication is seamlessly supported if the logger service account has database access.
Use the following SQL script to create your target table. Use DATETIME2 instead of DATETIME for higher precision timestamping, which is critical for high-frequency industrial serial logging.
CREATE TABLE SerialData ( RecordID INT IDENTITY(1,1) PRIMARY KEY, LogTime DATETIME2 DEFAULT SYSUTCDATETIME(), PortID NVARCHAR(20), SensorReading FLOAT );

Microsoft SQL Server connector in our logger.

SQLServer database connection settings. For example, SQL Express

SQL queue.
3. Protocol-Specific Troubleshooting
- Timeout or CRC errors: Unlike TCP, serial MODBUS RTU relies on strict timing. Verify that your RS485 A/B wires are not inverted, and that the baud rate and device ID in the software exactly matches the slave device.
- The device returns the "Illegal address" error code: Try to use the function #3 instead of the function #4 in your MODBUS request. Otherwise, verify that you are using the correct registe address. Try to specify an absolute offset (not logical address like 40001).
- I have several values that I want to export in one data row. Now, the logger writes one value per row: You need to enable the "Export all data at once" option in the MODBUS plugin settings.
4. Database-Specific Troubleshooting
- Login failed for user / Access Denied: If running RS232 Data Logger as a background Windows Service, ensure the service is running under a domain account with db_datawriter roles, rather than the default 'Local System' account. Or create a separate user with the 'SQL Server' authentication method.
- What if my database is offline? Will I lose my data?: Use the SQL Database Pro plugin. It can write data to a temporary file while your database is offline and restore it later.
- The code only works when you send numbers. When I'm trying to send a letter, it does not work.: 1. You should declare the parser variable as a string. 2. Your table should contain the column with the 'VARCHAR' or 'NVARCHAR' type. The size of this column should be enough for your data. 3. You should select the 'string' data type for the corresponding column in the data export plugin on the 'Binding' page.