Retrieving History Data
- Last UpdatedAug 21, 2026
- 1 minute read
History data retrieval through the Historian SDK consists of the following steps:
- Create an instance of the HistoryQuery class.
- Create an instance of the HistoryQueryArgs class and provide all parameters of the query, such as the tag names, start time, end time, and so on.
- Start the query using the HistoryQuery.StartQuery() method.
- Call the HistoryQuery.MoveNext() method in a loop until it returns false to fetch all data rows one by one. Each row is represented as an instance of the HistoryQueryResult class with properties matching the corresponding columns of the History table of the Runtime database.
- End the query by calling the HistoryQuery.EndQuery() method to release immediately all resources allocated by the query object.
Example
HistoryQuery query = historian.CreateHistoryQuery();
HistoryQueryArgs queryArgs = new HistoryQueryArgs();
queryArgs.TagNames.Add("MyDoubleByteStringTag");
queryArgs.StartDateTime = new DateTime(2012, 9, 1, 0, 0, 0);
queryArgs.EndDateTime = new DateTime(2012, 9, 30, 0, 0, 0);
queryArgs.RetrievalMode = HistorianRetrievalMode.Delta;
queryArgs.DataVersion = HistorianVersionType.Latest;
HistorianAccessError error;
if (!query.StartQuery(queryArgs, out error))
{
Console.WriteLine("Failed to start query: {0}", error.ErrorDescription);
}
while (query.MoveNext(out error))
{
Console.WriteLine("DateTime = {0}, vValue = {1}, OPCQuality = {2}, QualityDetail = {3}",
query.QueryResult.EndDateTime, query.QueryResult.StringValue,
query.QueryResult.OPCQuality, query.QueryResult.QualityDetail);
}
if (!query.EndQuery(out error))
{
Console.WriteLine("Failed to end query: {0}", error.ErrorDescription);
}
The HistoryQuery.QueryResult class has properties corresponding to columns of the History table when you perform a T-SQL query using Microsoft SQL Server Management Studio. However it does not include the DateTime property matching the column of the same name. You should use the EndDateTime property instead.