A PLC is designed to control a process, not to serve reports. Getting data out of it is a separate engineering problem: choosing an interface the controller supports, sampling at a rate that matches the process, preserving quality and time, and storing the result in a schema that can answer questions later.
These answers start with the interface and end with the schema and the failure modes. The arithmetic matters; a collection design that looks reasonable on a whiteboard can produce millions of rows a day or a database that cannot be queried at the rate it is written.
How to read these answers. Answers describe general practice and the versions named. PLC firmware, driver support, and network design vary by vendor and model; confirm the supported path for the specific controller.
Interfaces and access
What the PLC exposes, and what the collection layer should use.
How do you get data from a PLC into SQL Server?
Read the PLC through OPC UA, a vendor driver, or Modbus; collect with a gateway or service; write to SQL Server in batches with a defined schema. Do not write directly from the PLC to SQL Server unless the controller is explicitly designed and supported for it.
The common path is PLC → OPC UA server or driver → collector → SQL Server. The collector can be an Ignition gateway, a Kepware server, a .NET service, or a dedicated historian. It handles polling or subscriptions, buffering, batching, and reconnects. SQL Server stores a row per sample or a row per event, depending on the schema.
- Confirm which protocol the PLC supports natively and which requires a gateway. An older S7 or Modbus device may need a protocol converter.
- Expose only the tags the collection needs. A read of the entire data block is convenient and usually wasteful.
- Choose a collector that can buffer locally and retry. The network between the plant and the database will fail at some point.
- Write in batches. Row-by-row inserts at high rate will bottleneck on the database, not the PLC.
- Store quality and timestamp with the value. A value without either is not a measurement.
Do you need to modify the PLC program to collect data?
Usually not for read-only collection. You may need to expose existing tags, unoptimize a data block, or add a communication routine. Changing control logic is a separate, higher-risk scope.
Most collection projects read tags that already exist. The work is on the communication side: confirming the tag names, data types, and access permissions, and making sure the controller allows the read. Siemens optimized blocks, for example, may need to be non-optimized or accessed through a supported method. Allen-Bradley controllers may need the tags in a controller-scoped or program-scoped layout the driver can browse.
If a value does not exist as a tag, adding one is a small logic change with a change-control consequence. It should be reviewed by the controls owner, tested, and documented. If the project needs a new sequence, interlock, or safety function, that is controls engineering, not data collection. Keep the read path and the control path separate.
OPC UA vs Modbus: which should we use?
Use OPC UA when the device supports it and you need typed data, quality, security, and discovery. Use Modbus when it is the only available protocol or the data is simple register values and the network is already segmented.
OPC UA carries a structured address space, data types, quality codes, timestamps, and certificate-based security. It is easier to model a machine as objects and attributes, and it is the better long-term interface for multi-vendor data. The tradeoff is more configuration and a heavier stack than a few holding registers.
Modbus is simple and widely supported, but it exposes registers without semantics. A value is a 16-bit word; whether it is a signed integer, a scaled float, or two registers in a particular word order is a convention you must document. Modbus also has no native quality or timestamp, so the collector has to supply them. For a small, stable device on a segmented network, that can be fine. For a plant-wide data model, OPC UA is usually the better investment.
Sampling and time
How often to read, and what the timestamp actually means.
Polling vs event-driven collection: which is better?
Poll at a rate that matches the process, and use subscriptions or change events when the source supports them and the value changes infrequently. Events reduce traffic; polling is simpler and more predictable.
A poll every second is appropriate for a tank level that moves slowly. A poll every 100 ms may be necessary for a fast cycle, but it also multiplies the network and database load. The process time constant, not the PLC scan time, should set the rate. Polling faster than the process changes produces redundant rows and hides nothing useful.
OPC UA subscriptions and event-driven drivers send a notification when a value changes or a deadband is exceeded. That is efficient for alarms and state changes. The tradeoff is that a missed subscription or a reconnect can leave a gap, and some reports need a regular sample even when the value is unchanged. A common design is a slow heartbeat poll plus event-driven records for changes.
How fast can PLC data be collected?
A PLC scan is milliseconds; collection over Ethernet is usually tens to hundreds of milliseconds. One-second collection is routine, 100 ms is feasible with a good design, and 10 ms requires careful engineering and is often unnecessary.
The limiting factors are the PLC communication load, the driver or gateway, the network, the number of tags, and the database write rate. Reading 500 tags every 100 ms is a different problem from reading five. The PLC's scan time matters because communication service can compete with control logic; keep the read load within the controller's capacity and test it under production conditions.
For high-rate data, collect at the edge into a local buffer or binary file, then move batches to the database. Do not assume SQL Server can absorb thousands of individual inserts per second without batching and indexing work. Decide what the process actually needs: a trend at one second, a waveform at 10 kHz, or an event at the moment a bit changes are three different designs.
How do you timestamp PLC data correctly?
Use the PLC timestamp when it is reliable and the collector timestamp when it is not, and store both when they can differ. Synchronize clocks, use UTC, and include a sequence or quality flag for stale data.
A PLC clock can drift or be reset on battery replacement. The collector's clock is usually better synchronized, but it records when the value was received, not when the process changed. For slow processes the difference is small; for a fast event it can matter. Store SourceTimestamp and ReceivedTimestamp as separate columns so the distinction survives.
Use datetime2(3) or datetimeoffset, not datetime. Put the gateway and database on NTP, and monitor drift. If the PLC supplies a sequence number or a cycle counter, store it; it is the best way to detect a missed or duplicated message. A timestamp alone does not prove that every event arrived.
SQL schema, volume, and recovery
The database design decides whether the data is usable six months from now.
How should PLC tag data be stored in SQL Server?
Use a narrow table with TagId, Timestamp, Value, Quality, and a batch or sequence key for high-rate time series. Use wider event tables when one row represents a complete business event. Index by tag and time, partition large tables, and define retention.
A narrow schema is flexible: one row per tag sample, with a foreign key to a tag definition table. It handles new tags without a schema change and supports time-range queries. The cost is row count. A wide table with one column per tag is easier to read for a fixed set of tags but requires a migration whenever the tag list changes.
For SQL Server, cluster on (TagId, Timestamp) or a partition-aligned key, use datetime2(3), and insert in batches. Keep the tag definition in a separate table with unit, description, and source. Add a quality column; a value without quality cannot distinguish a real zero from a failed read. For very large volumes, partition by time and archive or aggregate older data rather than deleting it without a plan.
How do you avoid duplicates and gaps in collected data?
Use a sequence number or a natural key, write idempotently, buffer during outages, and reconcile counts after a reconnect. A gap is often a communication failure; a duplicate is often a retry.
The source should provide a monotonic sequence or a cycle counter when possible. The collector stores it with the sample, and the database enforces a unique key on the tag and sequence. A retry that arrives twice is rejected or merged rather than inserted again. If the source has no sequence, use the tag, source timestamp, and value as a composite key, accepting that two identical samples at the same timestamp are indistinguishable.
For gaps, monitor the expected sample count per interval and compare it with the actual count. A store-and-forward buffer can replay after an outage, but it can also create duplicates if the receiver is not idempotent. After a reconnect, run a reconciliation query for the outage window. Do not assume that a successful reconnect means the data is complete.
How do you detect machine states and cycles from PLC tags?
Build an explicit state model from a small set of bits and values, debounce transitions, and store state changes as events rather than inferring them later from raw samples. A cycle counter or start/end bit is more reliable than guessing from motor current.
Start with the signals the PLC already has: run command, ready, fault, cycle start, cycle complete, part present, and a cycle counter. Define states such as idle, running, faulted, and blocked. On each scan or poll, evaluate the transition, debounce it for a configured time, and write a state event with the previous state, new state, and timestamp.
Example
A mixer cycle is Idle → Filling → Mixing → Discharging → Idle. The collector writes one row per transition and one row per completed cycle with start, end, recipe, and operator. OEE and cycle-time reports query the event table instead of reconstructing the cycle from 10,000 temperature samples.
If the PLC has no cycle counter, add one in the control logic with the controls engineer's approval. Inferring cycles from an analog signal is possible but fragile.
Sizing, security, and failure
The numbers and boundaries that decide whether the design survives contact with the plant.
How much data and storage will collection produce?
Multiply tags by samples per second by seconds per day, then by bytes per row and retention. Two hundred tags at one sample per second is about 17 million rows a day before compression and indexes.
The arithmetic is simple and usually surprising. 200 tags × 1 sample/second × 86,400 seconds = 17.28 million rows per day. At roughly 30–60 bytes per row plus index overhead, that is about 0.5–1 GB per day before compression. A year is 180–365 GB. At 100 ms, multiply by ten.
Reduce the volume before adding storage: sample at the process rate, use deadbands for slowly changing values, store events rather than repetitive states, and aggregate old data. SQL Server compression and columnstore indexes can help, but they do not replace a retention policy. Decide how long raw data is kept, what is aggregated, and who can approve deletion. The retention decision is a business decision, not a DBA preference.
How do you secure PLC data collection?
Keep the collection path read-only, segment the OT network from IT, use a DMZ or broker, authenticate the collector, and never expose a PLC directly to the internet. Security starts with the network path.
The collector should read, not write, unless a write is explicitly designed and approved. Put the collector on a network segment that can reach the PLCs it needs and the database it needs, and nothing else. Use a firewall rule per destination and port. If data must cross from OT to IT, terminate the connection in a DMZ or through a brokered gateway rather than allowing a direct route.
Use OPC UA security policies and certificates where supported, or a segmented network with a trusted gateway where they are not. Give the collector a dedicated account with the minimum rights. Log who changed the configuration, and monitor for new connections. A flat network with a shared administrator password is the most common weakness in an otherwise well-designed collection system.
What are the common failure modes of a PLC collection system?
Stale values presented as live, silent gaps, buffer overflow, clock drift, schema changes, and a collector that reconnects but never catches up. Monitor freshness and counts, not just connection status.
A green connection indicator only says the socket is open. The value can be minutes old, the quality can be bad, or the buffer can be full. Monitor the age of the newest sample per tag group, the count of records per interval, the buffer depth, and the last error. Alert on freshness before the report is wrong.
Other failures are quieter. A PLC clock drifts and the trend shifts with it. A vendor firmware update changes a data type. A database login expires and the collector keeps retrying into a full disk. A schema change adds a column with no default and the insert starts failing. Each of these is detectable with a small set of checks; none is detectable from a connection light.
Engagement and first steps
The interface and storage decisions that shape the collection design.
Should we use OPC UA or a native driver?
OPC UA is preferable where it is available, licensed, and configured with a usable address space and security policy. A native driver may be necessary for an older controller or a specific data structure.
The assessment confirms what the controller actually exposes rather than what the product family supports. A gateway with a consistent tag model is often the better answer in a mixed environment.
Can you collect data from several vendors' PLCs?
Often, through OPC UA, a gateway, or protocol-specific drivers. The constraint is licensing and support for each protocol, not the collector's ability to hold several connections.
Mixed environments are common and usually argue for a gateway with a consistent tag model. The tag naming, data types, and quality codes should be normalized before the data reaches the database, or every report will need vendor-specific logic.
Where should the data live: SQL Server or a historian?
Use a historian for high-rate time-series values and trend queries; use SQL Server for production events, identifiers, and records that join to business data.
A common architecture writes both and links them by equipment, batch, and time window. The historian answers “what was the trend?” and SQL Server answers “which work order, lot, and test result does this belong to?”
What is the best first step?
Book a free 40-minute session, or send the question, the signals, the controllers, and the refresh rate.
Start with the question the data must answer and the tags that carry the answer. A short list of signals, the controller models, and the desired refresh rate is enough to frame the next step.
These answers cover data collection software and architecture. Control logic changes, safety-system work, and equipment commissioning belong to a qualified controls engineer and the plant's change-control process.
Back to the full PLC & Industrial Data Acquisition service page