Retrieving Events
- Last UpdatedAug 21, 2026
- 2 minute read
The Historian SDK allows an application to retrieve events stored in the history blocks. To retrieve events stored in the A2ALMDB database, you should use other methods such as the Microsoft ADO interface.
To retrieve events from the historian server, you must have a physical connection to it. Ensure this by checking the ConnectedToServer property of the HistorianConnectionStatus object.
To check the ConnectedToServer property of the HistorianConnectionStatus object
- Event retrieval through Historian SDK consists of the following steps:
- Create an instance of the EventQuery class.
- Create an instance of the EventQueryArgs class and provide all parameters of the event query, such as the ordering type, start time, end time, number of events, and so on.
- Start the event query using the EventQuery.StartQuery() method. 4. Call the EventQuery.MoveNext() method in a loop until it returns false to fetch all events one by one as HistorianEvent objects.
- End the event query by calling the EventQuery.EndQuery() method to release immediately all resources allocated by the query object.
Example
HistorianAccessError error;
EventQueryArgs eventQueryArgs = new EventQueryArgs();
eventQueryArgs.EventOrder = HistorianEventOrder.Ascending;
eventQueryArgs.StartDateTime = new DateTime(2014, 9, 1, 0, 0, 0);
eventQueryArgs.EndDateTime = new DateTime(2014, 9, 30, 0, 0, 0);
eventQueryArgs.EventCount = 1000;
EventQuery eventQuery = historian.CreateEventQuery();
if (!eventQuery.StartQuery(eventQueryArgs, out error))
{
Console.WriteLine(“Failed to start query: {0}”, error.ErrorDescription);
}
while (eventQuery.MoveNext(out error))
{
Console.WriteLine(“EventTime = {0}, EventId = {1}”,
eventQuery.QueryResult.EventTime, eventQuery.QueryResult.ID);
}
if (!eventQuery.EndQuery(out error))
{
Console.WriteLine(“Failed to end query: {0}”, error.ErrorDescription);
}
To retrieve events for certain properties, you can use the EventQuery.AddEventFilter() and EventQuery.AddEventFilterCondition() methods to specify a filtering rule for capturing only required events. The EventQueryArgs.EventCount property specifies the maximum number events to be returned in the query. If all events passing the filter need to be retuned, then EventCount must be set to 0. The EventQueryArgs.SkipCount property specifies the number of filtered events to be skipped before the first filtered events gets returned by the EventQuery.MoveNext() method.