# Problem with querying history

**URL:** <https://forum.inductiveautomation.com/t/problem-with-querying-history/40127>\
**Category:** Module Development\
**Created:** [October 29, 2020, 10:50am UTC](https://forum.inductiveautomation.com/t/problem-with-querying-history/40127 "2020-10-29T10:50:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [October 29, 2020, 10:50am UTC](https://forum.inductiveautomation.com/t/problem-with-querying-history/40127/1 "2020-10-29T10:50:39Z")

</div>

Hello,

I’m trying to develop a module that queries tag history data from the last 20 minutes. I’m not sure if im setting up the BasicTagHistoryQueryParams right or if I’m storing data in the DataStream correctly because I keep getting this error in the logs:

E ResultWriter 28Oct2020 11:39:12 Error executing historical tag read.

This is the code that I’m working with. Note that as it is right now, the StreamingDataset is not storing any data.

```auto
private float queryHistorian(ArrayList<TagPath> tagPaths) {

        StreamingDataset dataStream = new StreamingDataset();

        try {

            BasicTagHistoryQueryParams params = new BasicTagHistoryQueryParams(tagPaths, minutesAgo(21), minutesAgo(1), -1, null, ReturnFormat.Tall, null, null);

            GatewayContext gatewayContext = GatewayHook.getGatewayContext();

            dataStream.initialize(columnNames, columnTypes, false, -1);

            gatewayContext.getTagHistoryManager().queryHistory(params, dataStream);

            dataStream.readFully();

            return function(dataStream); //returns the value that I need using the DataSet from the last minutes

        } catch (Exception e) {

              logger.info(e.getClass() + " " + e.getMessage());

        } finally {
            dataStream.finish();
            return function(dataStream);

        }
    }

```

Column names and column types are the ones found on sqlt\_data\_x\_x\_x here: [https://docs.inductiveautomation.com/display/SE/Tag+History+Tables+Reference](https://docs.inductiveautomation.com/display/SE/Tag+History+Tables+Reference)

If I could get any input on what’s wrong with the code or an example of a better way to query the tag historian it would be very appreciated.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mlunapinel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mlunapinel/32/19719_2.png) [@mlunapinel](https://forum.inductiveautomation.com/u/mlunapinel)\
**Post date:** [November 3, 2020, 12:21pm UTC](https://forum.inductiveautomation.com/t/problem-with-querying-history/40127/3 "2020-11-03T12:21:26Z")

</div>

The problem was solved using BasicStreamingDataset instead of StreamingDataset.

```auto
private float queryHistorian(ArrayList<TagPath> tagPaths) {
        BasicStreamingDataset dataStream = new BasicStreamingDataset(Arrays.asList(columnNames.clone()), Arrays.asList(columnTypes.clone()));
        try {
            BasicTagHistoryQueryParams params = new BasicTagHistoryQueryParams(tagPaths, minutesAgo(21), minutesAgo(1), -1, null, ReturnFormat.Tall, getAliases(tagPaths), null);
            GatewayContext gatewayContext = GatewayHook.getGatewayContext();
            gatewayContext.getTagHistoryManager().queryHistory(params, dataStream);
            return media(dataStream);
        } catch (Exception e) {
            logger.info(e.getClass() + " 1 " + e.getMessage());
        } finally {
            dataStream.finish();
            return function(dataStream);
        }
    }

```
