Edit the tags database during run time
You can use the Tags Database (TagsDB) functions to add and remove project tags, classes, and class members during run time, as well as to configure properties and alarm conditions on project tags.
There are several important things to keep in mind when using the TagsDB functions, because they do much more than set and get tag values. They actually change the structure of the tags database, which can cause serious problems for a running project and all connected clients if it is not done properly. As such, most of the TagsDB functions can be executed only under the following conditions.
First, the InduSoft Web Studio development application must be installed and running on the project server, it must be fully licensed for Engineering+Runtime, and the project must be open in the application. The TagsDB functions use the development application’s database editor in essentially the same way that you do when you manually edit your project during run time. Because of this limitation, the TagsDB functions cannot be used at all in projects designed for and downloaded to Windows Embedded devices.
- The functions can be called from the Startup Script (which is executed when the project itself is run), Script Groups (which are continuously executed by the Background Task), and any Global Procedures called by them; and
- The functions cannot be called from the Graphics Script (which is executed separately by each client), Screen Scripts (which are attached to individual screens), and Command animations.
- Create a Global Procedure to call the TagsDB functions, and then call the function RunGlobalProcedureAsync to run that procedure; or
- Create a Script Group to call the TagsDB functions, configure a tag/expression to control the execution of that Script Group, and then change the value of that tag/expression.
Third, in any script that calls TagsDB functions to make structural changes to the tags database, you must first call the function TagsDBBeginEdit in order to lock the database for editing and prevent any other run-time changes. Then, at the end of the script, you must call the function TagsDBEndEdit in order to finish the changes that were made and allow the database to resume normal run-time behavior. Both functions must be called in the same script, because that script (more specifically, the program thread running that script) effectively owns the tags database while it is locked. You cannot call TagsDBBeginEdit in one script and then call TagsDBEndEdit in another.
When a project is edited during run time, the project server and every connected client must be updated with the changes as they are made. Normally, this is not a problem when you manually edit your project, because you make your changes slowly and one at a time. In contrast, the TagsDB functions allow you to make a large number of changes quickly, so updating the project server and the connected clients with all of those changes while the project is running can severely decrease run-time performance. Therefore, to maintain performance and protect the tags database, the project runtime — including all background tasks such as alarms, trends, and other scripts — is effectively paused and the changes are applied as a batch.
Restarting the project may or may not unlock the database, depending on how you designed your project and which script locked the database in the first place. Instead, you should use the Database Spy to manually call the function TagsDBEndEdit. When that is executed successfully, you can safely restart your project.