bg

Logging Data From Water Meters to MS SQL Database In Real-Time

A complete guide to polling RS232-interfaced water meters and exporting the captured data directly into a MsSQL database with your database structure.

1. Protocol Configuration: Flow & Water Meters

Communication Type: Active Polling (M-Bus / MODBUS)

Industrial water meters usually communicate via M-Bus (Meter-Bus) over RS232/RS485 using a level converter. Use the 'M-Bus Data Parser' plugin. The logger sends a REQ_UD2 (Request for Class 2 Data) frame to the specific meter address, and the parser will decode the responding telegram into volume, flow rate, and temperature variables.

Apply this base configuration for the serial connection:

{
  "port": "COM2",
  "baud_rate": 2400,
  "data_bits": 8,
  "stop_bits": 1,
  "parity": "even",
  "protocol": "mbus_en13757",
  "poll_interval_ms": 60000
}
M-Bus plugin selection to read water meter data.

M-Bus plugin selection to read water meter data.

M-Bus plugin configuration.

M-Bus plugin configuration.

Ready to connect Flow & Water Meters 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.

Microsoft SQL Server connector in our logger.

SQLServer database connection settings. For example, SQL Express

SQLServer database connection settings. For example, SQL Express

SQL queue.

SQL queue.

3. Protocol-Specific Troubleshooting

  • Receiving garbage hex data instead of M-Bus telegrams: M-Bus strictly requires Even parity. Check your COM port settings in the Data Logger and ensure it is set to 8 Data Bits, 1 Stop Bit, and Even Parity.
  • The logger displays non-readable data (strange characters) instead of expected HEX codes: You need to change the "Data View" mode in logger's settings. Select "Display as #XX" for all byte ranges.
  • What values can the logger read: M-Bus allows the logger to read all available values at once. The logger exports them as separate values (variables).

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.

Ready to connect Flow & Water Meters to Microsoft SQL Server?

Product Buy Download Support Contacts Site map
Copyright © 1999 - 2026, AGG Software.
All rights reserved.. Terms of use | Privacy policy