IMD SolutionComputing LibraryShop main store

Troubleshooting

Reading default historian data in SQL Server the supported way

Edge computing and IIoT Published 8 min read

Short answer

Attaching a SQL Server DSN to the SystemHistorian tag does store the historian's tables in SQL Server, but they are keyed to internal tag IDs, not tag names. Keep the default historian as the store and read the data through the REST SQLQuery endpoint, building an ID-to-name lookup from the Parms tables and paging large ranges in blocks of about ten thousand records.

On this page
  1. Why do the historian tables in SQL Server not match my tag names?
  2. Should I store VTScada history in SQL Server or keep the default historian?
  3. How do I query the default historian through the REST SQLQuery endpoint?
  4. How do I map internal tag IDs back to tag names?
  5. How do I query history values for a named tag?
  6. Why does a large history query return only part of the data?
  7. What do I check when a REST historian query returns nothing?
  8. Questions asked

You attached a SQL Server DSN to the SystemHistorian tag, restarted the application, and SQL Server now holds tables full of your history under names that match nothing in the tag browser. Nothing failed: those tables are the historian's storage layout, keyed to internal tag identifiers instead of the tag names. The supported read path is not to browse them in Management Studio. It is to query through the REST SQLQuery endpoint, the read-only ODBC server or a built-in report, with an ID-to-name lookup from the Parms tables whenever you need names. Keep the historian's storage where it is unless another system must query the rows directly; the sections below give the queries, the pagination arithmetic and the checks that prove each result.

Why do the historian tables in SQL Server not match my tag names? #

Your DSN did work: the SystemHistorian tag wrote the historian's storage tables into your SQL Server database, but those tables are keyed to internal tag identifiers rather than the tag names you see in the VTScada tag browser, so nothing in them looks familiar.

The DSN you named on the SystemHistorian tag is a storage target, not a query interface. The check that storage works is two-part: the DSN test connects, and new tables appear in the target database once the application is running again. The unfamiliar naming is by design, because the schema serves the historian's writer and reader, not a person browsing in Management Studio.

What you set up What it does What it is not
SQL Server DSN named on the SystemHistorian tag Storage target: the historian writes its schema and rows there after the restart A query interface for the historian
VTScada ODBC driver and server Gives external ODBC clients read-only SQL access to VTScada data, including the historian A way to move history into SQL Server
Default (integrated) historian VTScada's own store, kept in a proprietary format A tag-named schema you can browse in Management Studio

VTScada is not the only historian that keeps its own store beside SQL Server; we answer the parallel question in whether the PI Data Archive stores tag data in SQL Server.

Should I store VTScada history in SQL Server or keep the default historian? #

Keep the default historian as your store unless another system must read the rows directly from SQL Server: the vendor's guidance is that its integrated historian is many times faster than a SQL database for SCADA-style history reads, and trends and reports slow down when SQL becomes the store.

If a consumer truly must read rows — a plant data warehouse, a customer's reporting database — the supported route is to point a single VTScada server at a SQL historian through the server list. The vendor's documentation says previously logged data should synchronize into the SQL historian, so verify the backfill on a test copy before you rely on it: pick three known tags and compare row counts and first and last timestamps against the original store.

Two costs come with the move. The first is query speed: trends, reports and any history query get noticeably slower, which is exactly the trade the decision rule avoids. The second is database licensing, because every distinct client that reads the SQL historian counts toward your SQL Server client access licensing — we size that count in how to size SQL Server CALs for historian clients.

Decision: operator screens, trends and VTScada reports stay on the integrated historian; systems that must read rows directly get the SQL historian; everything else reads through REST or ODBC.

How do I query the default historian through the REST SQLQuery endpoint? #

Send an HTTP GET to the REST SQLQuery endpoint on the VTScada server with your SQL statement in the query parameter, and the historian answers with JSON; a browser address bar is enough for a first test.

The URL shape from the vendor's REST examples is:

http://ServerName:Port/Realm/REST/SQLQuery?query=SELECT%20*%20FROM%20Parms_ContextTag

ServerName, Port and Realm stand for your server's host name, its web port and the application's realm name; the SQL travels in the query parameter, URL-encoded, so every space becomes %20. That example is also the smoke test: SELECT * FROM Parms_ContextTag returns every context tag in the application as JSON. If it does, the REST service, the realm, the port and your access rights are all correct. If it fails, the fault is in the URL, the realm, the port or the rights — not in the historian.

How do I map internal tag IDs back to tag names? #

Read the configuration tables over the same REST endpoint: SELECT * FROM Parms_ContextTag returns every context tag, and Parms_AllTypes carries the tag properties, so build the ID-to-name lookup from those rows before any history query.

Pull the tag properties with the documented query:

SELECT Name, ShortName, Description, Area, Value FROM Parms_AllTypes

Send it as the query value on the SQLQuery URL. Your build may expose the unique ID under a column name of its own, so run SELECT * FROM Parms_AllTypes once and read the column list from the returned JSON instead of assuming one. With name and ID side by side you can join the SQL Server tables to the lookup by ID, or — simpler — keep each tag's full path from the lookup and use it in the REST history queries of the next section. If you would rather not build the lookup at all, the tag export to Excel in the application settings carries the same name-and-ID pairing.

Pick one logged tag, find its row in the lookup, and keep its full path: that path is the input the history query in the next section must return values for.

How do I query history values for a named tag? #

Query the History_ tables over REST and select the column named after the tag path plus its data type and statistic — for example path:Value:Average — aliasing each column with AS so the JSON comes back readable.

The table suffix carries the resolution: History_1S holds one-second rows and History_15M holds 15-minute rows. The latest value for two tags, in the shape of the vendor's documented example, uses their demo tag paths — replace them with yours from the lookup:

SELECT Timestamp,
  Liftstations\LS1\Pumps\Pump1\Flow:Value:Average AS 'Liftstation 1 - Pump 1 - Flow',
  Liftstations\LS1\Pumps\Pump1\Running:Value:Average AS 'Liftstation 1 - Pump 1 - Running'
FROM History_1S LIMIT 1 ORDER BY Timestamp DESC

A time-bounded read from the 15-minute table, with an illustrative date:

SELECT Timestamp,
  Liftstations\LS1\Pumps\Pump1\Flow:Value:Average AS 'Pump 1 Flow'
FROM History_15M
WHERE Timestamp > '2024-06-08 20:00:00' LIMIT 100

In a URL, the space inside the timestamp literal becomes %20. The test that proves the setup: the latest-value query returns exactly one row, and its value matches what the tag shows on the operator screen at that moment. A row with a stale or empty value points at logging, not at the query: check that the tag logs at the resolution you queried.

Why does a large history query return only part of the data? #

The REST interface paginates large results to protect the server, and the default maximum block size is reported at roughly ten thousand records, so a 30-day read from the one-second table at one value per second needs about 260 requests.

The limit is adjustable if you would rather not page, but a bigger block loads the same server that runs your operator screens, so the safer habit is to page. Your version's REST documentation names both the block-size setting and the continuation mechanism for walking the blocks; follow it rather than guessing parameter names.

Worked example, one tag logged once per second, queried over a 30-day range:

  • Samples in range: 30 days × 24 h/day × 3600 s/h = 2,592,000 records.
  • Requests at the reported block size: 2,592,000 ÷ 10,000 = 259.2, rounded up to 260 requests.
  • Same range from the 15-minute table: 30 × 24 × 4 = 2,880 records, so one request.
  • A tag logging once a minute over the same range: 30 × 24 × 60 = 43,200 records, and 43,200 ÷ 10,000 = 4.32, so 5 requests.

Decision: page the fine-resolution table only for the exact window you will plot, and drive dashboards and long ranges from the coarsest table that answers the question. If aged data can drop to a coarse resolution permanently, do it at the store — we show reducing stored historian data older than six months to ten seconds and every later query over that data shrinks with it.

Pagination is the standard way a data service protects itself from oversized reads; the same design choice appears in pagination for large node sets in OPC UA browsing.

Prove a paged read with a count: the row counts summed across all blocks must equal the count from a narrow-window query over the same range.

What do I check when a REST historian query returns nothing? #

Work the failure in order — connection, realm, query, data — and most empty results trace to a wrong realm name or port in the URL, an unlogged tag, or a time window with no stored samples.

Run these in order and stop at the first failure:

  • Storage: the DSN test connects and the tables appeared after the restart. That proves storage only; it says nothing about readback.
  • REST service: SELECT * FROM Parms_ContextTag returns JSON. A failure here means the URL, realm, port or access rights — fix it before touching history queries.
  • Tag logging: rows exist in one History_ table but not another, or in none. The tag is not logged, or you queried a resolution it does not write; check the tag's logging settings.
  • Column name: a query that errors on the tag path has a backslash or colon problem, or an unencoded space. Copy the exact path:Value:Average form from the working latest-value example.
  • Client difference: the query runs in one tool and returns nothing in another. Suspect the connection, the account or the encoding before the SQL itself.
  • Truncation: a wide range returns fewer rows than the arithmetic above predicts. That is pagination, not data loss — walk the blocks.

The decision, in every case: keep the integrated historian as the store, read it through the REST endpoint or the ODBC server, and reserve SQL Server storage for the consumers that cannot read any other way.

Questions asked

Can Excel read the default historian directly?

Yes. The SQLQuery URL is an ordinary web address, so an Excel web query can call it the same way a browser or a script does: paste the percent-encoded URL where the connection asks for the address, and the JSON rows arrive like a queried table. For a range wider than one block, script the requests and append the blocks, rather than raising the block size on a server that also runs your operator screens.

Should the storage DSN be a User DSN or a System DSN?

A User DSN is visible to the Windows session that created it. If the VTScada service runs under a different account, that account may not see the DSN, so a System DSN is the safer choice. The DSN must also match the bitness of the ODBC administrator you used to create it. These are general ODBC behaviors, not VTScada settings, so confirm them against your service account before the restart.

How do I find which user created a tag?

Run SELECT * FROM Parms_ContextTag and read every returned column name, looking for a creator or modification field. If your build records authorship, filter on that column and compare against one tag created by each of your users. If no column carries it, the Parms tables hold no provenance: enable the configuration-change record your VTScada version documents before the next edits, because nothing can reconstruct who created past tags. Alarm history queried by operator is an event record, not tag authorship.

Where does the default historian keep data if no DSN is attached?

In a proprietary format under the application's Data folder; the storage location property for the SystemHistorian tag, SystemHistorianStorageLocation, defaults to that location. The files are not readable tables, which is why reads go through the REST endpoint, the ODBC server or a report, and why attaching SQL Server storage produces the ID-keyed schema you found.

Keep reading

  • Troubleshooting

    Citect Historian 2016 slow retrieval as SQL tables grow

    Retrieval slow in both the Citect Historian Excel tool and a direct SQL query is a response-time problem in the SQL history tables, which grow with every historized row. Lower over-fast storage rates, purge to your retention, reindex, and start the migration to AVEVA Historian, since end of support for Citect Historian has been announced.

    Edge computing and IIoT

  • Explainer

    Do you need a historian or just an OPC tag server?

    No. An OPC tag server (OPC DA) supplies the current value, quality and timestamp of each item and stores nothing, so monthly figures need a historian or a SQL logger collecting from that same server. Keep a reporting client like ActiveFactory only if you also run the historian it expects.

    Edge computing and IIoT

  • Troubleshooting

    Edge trend shows no historian data: fix the doubled SELECT

    The trend stays blank because a complete SELECT statement was pasted into the Table field, so the gateway wraps it in its own SELECT ... FROM and SQL Server rejects the result as incorrect syntax near the keyword select. Put only Runtime.dbo.History in Table, carry DateTime, TagName and Value in the column controls, and move TagName = 'SysTimeSec' into the filter control.

    Edge computing and IIoT