IMD SolutionComputing LibraryShop main store

How-to

Retrieve manually inserted historian values into InTouch tags

Edge computing and IIoT Published 7 min read

Short answer

Manual-acquisition tags are stored by the Historian but never pass the runtime window that the InTouch access name aahiosvrsvc serves, so the live-value connection returns nothing. Retrieve the newest sample of each tag with a windowed SQL query against the Runtime history view, then assign each row to its InTouch tag by TagName in script.

On this page
  1. Why the live-value access name returns nothing
  2. What the query must promise
  3. Step-by-step: query the view and map by tag name
  4. Worked example: newest sample for four once-a-minute KPI tags
  5. Mapping rules that keep the display honest
  6. Inline query or stored procedure
  7. Keep the access name for acquired tags
  8. Questions asked

Manual-acquisition historian tags do not come back through the InTouch SuiteLink access name, and no access-name setting changes that: a programmatically inserted value never enters the acquisition path that live-value retrieval serves, so the SuiteLink item has nothing to deliver. Read those values where they were stored. Run a windowed SQL query against the Runtime history view from InTouch scripting, take the newest row for each TagName, and assign it to its destination tag by name. This covers why the live path fails, the query and script that work, a worked example for four once-a-minute KPI tags, and the mapping rules that keep the display honest.

Why the live-value access name returns nothing #

The standard InTouch route to historian live values is an Access Name with application name aahiosvrsvc and topic tagname, addressing each historian tag by name as the item. That route serves values the historian acquired from an I/O server: AVEVA's historian documentation calls I/O-server acquisition the typical source, delivered over SuiteLink or DDE, and Wonderware Historian documentation separates the manual data acquisition service (MDAS), which accepts data for non-I/O-server (manual) tags. Acquired values pass through the runtime window that live-value retrieval reads. A programmatic insert writes history and skips that window, so the item name resolves but the value never arrives, which is exactly what you see: history queries return rows while the live tag stays empty.

The failure is structural, not a settings error. For tags the historian itself acquires and serves live, writing calculated tags to AVEVA Historian readable via SuiteLink covers the working readback configuration. For deciding how programmatic values should be written in the first place, manual lab data entry into a historian: choosing the write path sorts the write-side options.

What the query must promise #

Fix the retrieval contract before writing code:

  • One newest stored sample per tag, not one newest row across all tags, which would discard the other three KPIs.
  • TagName, DateTime and Value in the result: mapping needs the name, staleness needs the timestamp.
  • A search window sized to the insert rate, not an exact timestamp. An equality predicate assembled from $DateString and $TimeString returns a row only when a sample exists at that instant, which a once-a-minute KPI usually misses.
  • Defined behavior for an empty window before an operator ever sees one.
  • Stored samples, not interpolated ones. If retrieval is set to calculate between samples, a returned row can be a computed value; check the returned DateTime against the insert schedule.

Step-by-step: query the view and map by tag name #

  1. Create one InTouch analog destination tag per KPI, one message tag per KPI for its newest sample timestamp, and one discrete staleness flag.
  2. On the historian's SQL instance, create a dedicated login whose only permission is read access to [Runtime].[dbo].[v_AnalogHistory]. No administrative accounts.
  3. In the script of the window that displays the KPIs, use System.Data.SqlClient.SqlConnection, System.Data.SqlClient.SqlCommand and System.Data.SqlClient.SqlDataReader; the connection string carries the server name, Database=Runtime, and the login from step 2.
  4. Execute the windowed query below, load the reader into a System.Data.DataTable, and close reader and connection on every path, including errors.
  5. Walk the table newest-first, which the query does for you. The first row seen for each TagName is that tag's newest sample in the window: fill its destination and timestamp tags, leave the flag clear.
  6. If a tag has no row in the window, or its Value is null or fails numeric conversion, keep the last good value and set the flag. Never write zero.
  7. Schedule the script to repeat while the window is shown; the worked example uses a 30 s interval.
SELECT TagName, DateTime, Value
FROM [Runtime].[dbo].[v_AnalogHistory]
WHERE TagName IN (
  'Mixer100_Temperature_PV_rate_hourly',
  'Mixer200_Temperature_PV_rate_hourly',
  'Mixer300_Temperature_PV_rate_hourly',
  'Mixer400_Temperature_PV_rate_hourly'
)
AND DateTime >= DATEADD(minute, -5, GETDATE())
ORDER BY DateTime DESC;

Using DATEADD(minute, -5, GETDATE()) puts the window boundary on the database server's clock, so a skewed InTouch station cannot shift the interval. The script core, exactly as it runs in the window script:

Dim sConnString As String;
Dim sSQL As String;
Dim objConn As System.Data.SqlClient.SqlConnection;
Dim objCmd As System.Data.SqlClient.SqlCommand;
Dim objDR As System.Data.SqlClient.SqlDataReader;
Dim objTbl As System.Data.DataTable;

sSQL = "SELECT TagName, DateTime, Value FROM [Runtime].[dbo].[v_AnalogHistory] "
     + "WHERE TagName IN ('Mixer100_Temperature_PV_rate_hourly', "
     + "'Mixer200_Temperature_PV_rate_hourly', "
     + "'Mixer300_Temperature_PV_rate_hourly', "
     + "'Mixer400_Temperature_PV_rate_hourly') "
     + "AND DateTime >= DATEADD(minute, -5, GETDATE()) ORDER BY DateTime DESC;";

objConn = New System.Data.SqlClient.SqlConnection(sConnString);
objConn.Open();
objCmd = New System.Data.SqlClient.SqlCommand(sSQL, objConn);
objDR = objCmd.ExecuteReader();
objTbl = New System.Data.DataTable();
objTbl.Load(objDR);
objDR.Close();
objConn.Close();

Column indexes follow the SELECT list: 0 is TagName, 1 is DateTime, 2 is Value. For row index i counted from 0, one assignment pair looks like this, and the walk applies it only the first time a TagName appears:

KPI_Mixer100 = objTbl.Rows[i][2];
KPI_Mixer100_Time = objTbl.Rows[i][1];

Worked example: newest sample for four once-a-minute KPI tags #

Inputs:

  • Tags: the four mixer KPI analog tags above, Historian acquisition type Manual, inserted programmatically by the KPI writer.
  • Insert rate: one sample per tag per minute (60 s), the writer's schedule.
  • Display poll: 30 s while the window is shown, chosen here.
  • Search window: 5 min (300 s), chosen here.

Rule in words: the window must span several insert intervals so missed inserts cannot empty the result, and the staleness limit must sit above the worst healthy sample age, which is one insert interval plus one poll interval.

Arithmetic:

  • Window capacity: 300 s ÷ 60 s per sample = 5 samples per tag; 4 tags × 5 samples = up to 20 rows.
  • Miss tolerance: a tag still returns a row until 4 consecutive inserts are missed (5 − 4 = 1 row left).
  • Worst healthy age: 60 s + 30 s = 90 s, a poll just before an insert and the next poll after it.
  • Stale limit: 120 s. Margin over worst healthy age: 120 s − 90 s = 30 s.

Result: every 30 s each destination receives its tag's newest stored sample, the timestamp tag shows when that sample landed, and once a tag's newest sample is older than 120 s the flag replaces the refresh.

Decision: for anything inserted once a minute, run a 30 s poll, a 5 min window and a 2 min stale limit. Scale the window and the limit with the insert period, five intervals for the window and two for the limit, and keep the poll at or below half the insert period so the margin never shrinks below half an interval.

Prove it: run the script right after a KPI insert and check in the installed historian client's query tool that each destination's Value and DateTime equal the newest row for that TagName, all four matched by name. Then pause the inserter: at 120 s of pause the flags appear while rows still return, and at 300 s the result set is empty and the flags hold, so the thresholds behave exactly as computed.

Mapping rules that keep the display honest #

  • Positional assignment, filling destinations from Rows[0] through Rows[3], works only by luck. The order of names in an IN list is not a row order, and with a window the rows interleave by time. Match by TagName.
  • Several rows per tag are the normal case once you query a window; that is why the walk takes the first row per name and skips the rest.
  • A null Value or a failed conversion to the destination's numeric type is a failed update. Keep the last good value and flag it, because writing zero turns a data fault into a believable process value.
  • The operator-facing rule: never show the number without its age. The timestamp tag and the flag travel with the value.

Inline query or stored procedure #

Start with the inline query: window, ordering and mapping sit in one screen of script where they run. Move the SELECT into a stored procedure when several clients need the same selection or the interval changes often. The procedure can hold the DATEADD window too, so every caller gets the same interval, and the login needs only EXECUTE on it instead of read access to the view. Scheduling, validation and tag assignment stay client-side either way.

When clients beyond InTouch need these latest values, exposing historian latest values over OPC UA or MQTT serves them from the historian instead of duplicating SQL in every client. The same newest-rows selection problem appears wherever a display polls a database; one client-side pattern worked through in Ignition Vision is configuring Ignition Vision to select newly inserted rows.

Keep the access name for acquired tags #

Leave the aahiosvrsvc access name in place for tags the historian genuinely acquires from an I/O server; that is its job. Do not convert the KPI tags to I/O-server acquisition just to light up the access name: that reroutes how data enters the historian, and the inserting code would have to imitate an I/O source to keep the runtime window fed. The query reads what was actually stored, touches nothing on the write side, and returns the newest sample with its timestamp attached. Read manual tags by query, acquired tags by access name, and let the timestamp decide trust.

Questions asked

Why does the aahiosvrsvc access name serve acquired tags but return nothing for manual ones?

Live-value retrieval serves the acquisition path: values an I/O server delivered through the runtime window. Manual-acquisition tags are stored through the historian's manual data path and never enter that window, so the SuiteLink item resolves but carries nothing. Confirm the split in one minute: the same tag name returns rows from the history view while its live item stays empty, and that combination is the signature of a manual tag.

Should I change the KPI tags to I/O-server acquisition so the access name works?

No. That changes how data enters the historian instead of how you read it, and the inserting code would have to imitate an I/O source to keep the runtime window fed. The SQL read returns the stored sample with no change to the write side, which is the smaller and safer move.

Is a stored procedure better than the inline query?

Use one when several clients need the same selection or the interval changes often, and the login then needs only EXECUTE permission instead of read access to the view. Note the trade: with the window logic server-side, one change updates every client at once, which is the benefit or the risk depending on who owns the database. The client still schedules, validates and assigns.

How old can the displayed value get before I treat it as bad?

Worst healthy age is one insert interval plus one poll interval: 60 s plus 30 s, or 90 s, in the worked example. Flag anything older than 120 s, which leaves 30 s of margin, and show the sample timestamp beside the value so the operator sees age, not just a number.

Which SQL account should the connection use?

A dedicated login whose only permission is read access to the history view on the Runtime database, never an administrator account. If the query later moves into a stored procedure, grant EXECUTE on that procedure instead. A limited account confines what a leaked or reused credential can reach.

Could the query hand back a value that was never inserted?

Yes, if retrieval is set to interpolate or calculate between samples. Keep stored-sample retrieval for this read and check the returned DateTime against the insert schedule: a stored sample carries an insert time, a computed one carries the requested boundary. If you ever want a calculated value, request it explicitly instead of inheriting one.

Keep reading

  • Troubleshooting

    Fix SLSping no reply to AVEVA Historian 2023 status tags

    Historian 2023 still serves status tags to a remote InTouch node over SuiteLink through the legacy Historian I/O Server, so SLSping should answer. Do not copy the 2020 aahiosvrsvc.exe hotfix into a 2023 install. The reported fix was enabling System Monitor Manager, permitting non-encrypted communication as a temporary diagnostic, then rebooting the InTouch client node.

    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

    Fix historian silent data gaps with a registry value

    The data is stored; the retrieval view of it is stale. On the Historian server, create the DWORD32 value UseFileCacheForRetrieval set to 0 under HKLM\SOFTWARE\ArchestrA\Historian\Programs\aahStorage, then refresh the trend, with no reboot required. Confirm the fix by loading a previously blank window before running any manual query.

    Edge computing and IIoT