QueryAsync function
QueryAsync() queries a SQL database for a specific set of data.
This topic provides information on configuring QueryAsync calls using either a private string standard (secured and recommended method) or a string value (unsecured method). By default, SQL queries can be executed only with the secured SQL query method (that is, using a private string standard). The unsecured SQL query method (that is, using a string value) is blocked. To provide users with the necessary time to migrate SQL database access to the secured method, you can temporarily enable unsecured access to SQL databases in DeltaV Live Administration, in the SQL Data Sources Management application. However, unsecured access will be removed in a future release of DeltaV.
- Arguments
- 2 or more, Optional arguments are indicated by the at symbol (@) following the number of the parameter, beginning with 1.
- Return values (string)
-
A Promise that awaits and then returns an array of rows, each row with an array of columns, all that meet the criteria.
- Syntax
- Syntax for the secured SQL query method (recommended):
SQL.<SQL Data Source>.QueryAsync(<private string standard reference>, <@1...@N>):string[][] - Examples
-
- Exceptions
-
It is considered best practice to configure a try-catch statement for possible exceptions that can be thrown, in order to display the appropriate exception message to users. Therefore, Emerson recommends configuring a try-catch block around all calls to QueryAsync. (For more information on handling exceptions, see the topic, Scripting tips for DeltaV Live, in the Related information section.)
The following table lists some of the possible exceptions that can be thrown and the strings each exception returns:
Possible exception String returned This DeltaV system either does not have the Premium-tier DeltaV Live engineering license, or that license is not assigned or downloaded. "This system is not licensed for Premium-level DeltaV Live engineering features: SQL Data Sources." The SQL Data Source name cannot be resolved. "SQL Data Provider does not exist for connection named: <SQL Data Source>." Cannot connect to the SQL database. "Could not open connection to <database name>" Unsecured SQL queries are blocked and cannot execute a string query value.
OR
Unsecured SQL queries are blocked, and the name of the private string standard value cannot be found or does not exist.
"Unable to resolve SQL query for standard value named: <SQL query name/value>." An error has occurred during query execution. "SQL query execution failed." No DeltaV user is currently logged in. "No user is logged in. Query execution is disabled."