# Client DataSet SQL Refresh

**URL:** <https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806>\
**Category:** Ignition\
**Tags:** ignition79, database\
**Created:** [September 25, 2018, 1:59pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806 "2018-09-25T13:59:10Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 25, 2018, 1:59pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/1 "2018-09-25T13:59:10Z")

</div>

Is there a way to update a client DataSet that is bound to a SQL query on demand?

I have a client dataset that pulls data from a database and polling is set to off. However if a record is added to the table by runtime I’d like to be able to force a refresh of that data to the dataset. Is there a way to do that without setting up polling?

---

<div class="post-metadata">

**Author:** ![dano38291](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@dano38291](https://forum.inductiveautomation.com/u/dano38291)\
**Post date:** [September 25, 2018, 2:31pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/2 "2018-09-25T14:31:29Z")

</div>

How or where is the record being added to the Table by runtime? Maybe some how reorganize your Client Dataset/ Graphic Objects so can call system.db.refresh() on a component. There’s polling and system.db.refresh(), not sure of ways of updating? I don’t think you can call system.db.refresh on a Client Tag?

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 25, 2018, 2:50pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/3 "2018-09-25T14:50:22Z")

</div>

I’m adding the row via a button on the gui so I know when it is getting updated. I tried the system.db.refresh but it didn’t like the client tag.

This is configuration data for a backend part of the system, so it won’t get updated often, but when it does get updated it would be nice to be able to refresh the table with the new data.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 25, 2018, 2:54pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/4 "2018-09-25T14:54:33Z")

</div>

There’s no supported way to refresh a Client Tag. Put the following in a shared or project script for an unsupported method:

```auto
from com.inductiveautomation.factorypmi.application import FPMIApp
from com.inductiveautomation.ignition.common.sqltags.parser import TagPathParser

# Support refresh of normally non-refreshing client expression tags and client SQL query tags
def refresh(tagname):
	tp = TagPathParser.parse(tagname)
	ctx = FPMIApp.getInstance().adapterContext
	node = ctx.tagManager.getTag(tp)
	node.startBinding(ctx, node.path)

```

EDIT: retrieve the adapterContext instead of the clientContext for all cases. Pretty sure this will work everywhere, in all recent Ignition versions.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 25, 2018, 3:11pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/5 "2018-09-25T15:11:50Z")

</div>

I stuck your code in a shared script and I got this error:

AttributeError: ‘com.inductiveautomation.factorypmi.application.FPM’ object has no attribute ‘clientContext’

BTW I’m using 7.9.9 if that matters.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 25, 2018, 4:05pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/6 "2018-09-25T16:05:03Z")

</div>

> [@bschroeder](#):
>
> and I got this error

See the edit above, using adapterContext in place of clientContext.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [September 25, 2018, 4:39pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/7 "2018-09-25T16:39:28Z")

</div>

> [@pturmel](#):
>
> from com.inductiveautomation.factorypmi.application import FPMIApp  
> from com.inductiveautomation.ignition.common.sqltags.parser import TagPathParser
> 
> # Support refresh of normally non-refreshing client expression tags and client SQL query tags
> 
> def refresh(tagname):  
> tp = TagPathParser.parse(tagname)  
> ctx = FPMIApp.getInstance().adapterContext  
> node = ctx.tagManager.getTag(tp)  
> node.startBinding(ctx, node.path)

Works like a charm.

So... related to this. Where would I find the latest API? The only one I can find is 7.8.4.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 25, 2018, 6:01pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/8 "2018-09-25T18:01:59Z")

</div>

> [@bschroeder](#):
>
> Where would I find the latest API?

This is the one I spend the most time with:

[http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/index.html](http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/index.html)

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [September 26, 2018, 9:08am UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/9 "2018-09-26T09:08:16Z")

</div>

Can’t you work with a tag as trigger? I often use this to refresh queries in the interface, but when I have no direct access to the table (f.e. adding a record from a popup).

Typically, I make a boolean tag, and then define the query like this:

```auto
SELECT MyColumn
FROM MyTable
WHERE Condition = 'whatever' AND
      {path/to/triggerBit} = {path/to/triggerBit}

```

Whenever the bit is toggled, the query is refreshed as one of the bound tags is changed, but the results are still the same (0=0 and 1=1 are always true).

I don’t know if this works on client tags though, I don’t use that very often. My queries tend to either be global (always return the same result for all clients), or UI-dependent.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [September 26, 2018, 2:13pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/10 "2018-09-26T14:13:51Z")

</div>

And just to be a party pooper, `FPMIApp.getInstance()` is deprecated and may be removed in 8+. It’s still there right now, but it’s fair game for removal at any time.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 26, 2018, 4:03pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/11 "2018-09-26T16:03:25Z")

</div>

> [@KathyApplebaum](#):
>
> it's fair game for removal at any time

Us module developers are kinda used to this, in general. Which is why I clearly noted this was unsupported. It'd be _ **nice** _ if there was an official way to refresh a client tag binding before y'all break this work-around. It'd be super-awesome if the official refresh operation worked on both bound client tags and your future gateway-side scan-class-less expression/query tags. (-:

---

<div class="post-metadata">

**Author:** ![ted.garrison](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ted.garrison/32/11732_2.png) [@ted.garrison](https://forum.inductiveautomation.com/u/ted.garrison)\
**Post date:** [February 7, 2020, 6:41pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/12 "2020-02-07T18:41:46Z")

</div>

Did this ever happen? I’m looking for the same thing right now. Have one tag using a Named Query that I would like to be able to have poll on-demand since I know when it needs refreshed. I don’t need a 5 second refresh if nothing has changed, and a 5 minute refresh is useless, as I need to see the new result set NOW.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 15, 2022, 1:02pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/13 "2022-06-15T13:02:35Z")

</div>

Is this still the case that there is no supported way to refresh a client sql tag that is not on polling? How can this be done in Ignition 8.1.17?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 4, 2023, 1:25pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/14 "2023-12-04T13:25:06Z")

</div>

Working on a project where this need appeared again, I need to do this again for 8.1.26. Is there a way to refresh a client tag that has a SQL Query or Named Query binding on demand programmatically vs relying on polling or a hacky workaround by changing a no-op parameter/changing a 0=0 to 1=1 in the where clause?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 4, 2023, 1:30pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/15 "2023-12-04T13:30:18Z")

</div>

Have you tried the unsupported approach above? (might need an update for v8.1)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 4, 2023, 1:31pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/16 "2023-12-04T13:31:51Z")

</div>

Yes just tried, the issue I am getting is on this line -  
`node = ctx.tagManager.getTag(tp)` throws me an AttributeError - has no attribute `getTag`.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 4, 2023, 2:17pm UTC](https://forum.inductiveautomation.com/t/client-dataset-sql-refresh/19806/17 "2023-12-04T14:17:37Z")

</div>

Yeah, new architecture. You'll have to get the client tag provider from the tag manager, then probably use [reinitializeTagsAsync()](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.30/com/inductiveautomation/ignition/common/tags/model/TagProvider.html#reinitializeTagsAsync(java.util.List)).
