Managing TSQL Monitoring Statements
Section titled “ Managing TSQL Monitoring Statements”Gain full control over your SQL Server monitoring with the Nodinite Database Monitoring Agent. This page shows you how to leverage custom TSQL scripts for proactive monitoring, instant alerts, and self-service management—empowering both integration experts and business users.
✅ Monitor SQL Server health and business data using your own TSQL logic
✅ Instantly receive alerts and automate remediation with Remote Actions
✅ Empower self-service for business users to execute pre-defined scripts
✅ Centralize monitoring and management for all your SQL Server resources

Animated walkthrough: the statement 'Contoso: Orders awaiting confirmation' is Error, and its THROW message is the Log Text. Details, then Show Action Scripts: Execute 'Show the orders awaiting confirmation', confirm, and read the seven orders in the result.
Automate your database monitoring and get alerts using your custom coded TSQL statements! Gain actionable insights and perform administrative tasks by executing pre-defined TSQL scripts—all from a single platform.
The Nodinite Database Monitoring Agent provides two major features for SQL Server:
- Monitoring – Get alerts from logic in custom-built TSQL statements
- Management – Allow end-users to execute pre-defined TSQL statements from one or more TSQL Script collections
Here's a visual overview of how monitoring and management features are organized in Nodinite.
To use the Monitoring feature, provide either Stored Procedures or Text/AdHoc TSQL statements. Implement your business logic using the examples on this page.
- Text/AdHoc
- Stored Procedures
New 7.13
A SQL Statement in the Nodinite Database Monitoring Agent is a group: one authentication (the connection string, and optionally impersonation) and a list of monitoring statements. Each enabled monitoring statement of an enabled SQL Statement is one Resource to manage, named after the monitoring statement's Display Name; the SQL Statement itself is not a Resource. Assign these Resources to one or more Monitor Views to trigger alerts according to the evaluated monitor state. Use the Nodinite Alarm Plugins to push alerts.
In the Monitor Views, the monitoring statements of Microsoft SQL Server share the SQL Statements Category, and their Application is the name of the SQL Server configuration.

Two monitoring statements of one SQL Statement, each its own Resource with its own Log Text: Failed orders: 0 and Open orders: 3.
One SQL Statement holds the connection for any number of monitoring statements; each enabled monitoring statement is one Resource to monitor.
What are the key features for Monitoring SQL Statements?
Section titled “ What are the key features for Monitoring SQL Statements?”- State Evaluation – Monitor and evaluate the state based on your custom TSQL logic. See the TSQL/Stored procedure code examples further down in this guide.
- Actions – Support for the execution of Remote Actions
How do SQL Statements evaluate?
Section titled “How do SQL Statements evaluate?”The following monitoring states exist:
| State | Status | Description | Actions |
|---|---|---|---|
| 🚫 Unavailable | Resource not available | Evaluation of the 'SQL Statement' is not possible either due to network or security-related problems | Review the prerequisites |
| ❌ Error | Error state raised | The SQL Statement is raising an exception to report that one or more major problems/errors exist | Edit |
| ⚠️ Warning | Warning state raised | The SQL Statement is raising a warning to report that one or more minor problems/errors exist | Edit |
| ✅ OK | Online | The SQL Statement is valid and reports that no problems exist | Edit |
A statement raises a state with THROW: state 1 is Error, state 2 is Warning, and the exception message becomes the Log Text, for example ERROR: 7 orders have waited more than an hour for their confirmation (limit 3). A statement that ends without an exception is OK. See the Text Example.
How do I add my custom coded TSQL Statements?
Section titled “ How do I add my custom coded TSQL Statements?”The Database Monitoring Agent automatically monitors each configured SQL Statement. The Nodinite Administrator can add new and modify existing SQL Statements using the Remote Configuration dialogue for the Database Monitoring Agent
Global Configuration
Section titled “ Global Configuration”In the Remote Configuration, open the SQL Servers tab and expand the SQL Server Instance accordion. Each instance has the tabs General, Advanced, Backups, Jobs, Size checks, SSIS, and SQL Statements. Click the SQL Statements tab.

The SQL Statements tab of an instance: one accordion per SQL Statement; a crossed-out entry is disabled.
The Nodinite Administrator can add new SQL Statements from the Remote Configuration dialogue, detailed in Add or manage a Monitoring Agent.
From the SQL Statements tab in the SQL Connection configuration, click the Add button.
You can add any number of SQL Statements. Make sure that each one executes quickly, or you may end up hogging the agent, resulting in timeouts.

Example to add a new configuration for SQL Statements using the Add button.
Then, expand the accordion.

The following tabs exist:
General tab
Section titled “ General tab”To manage the essential configuration, click on the accordion to expand the details:

The General tab of a SQL Statement; the tab names count its monitoring statements and action scripts.
You can manage the following properties:
- Enabled – When checked, the monitoring statements of this SQL Statement are monitored. Clearing it removes the Resources of all its monitoring statements from the Monitor Views.
- Display Name – The name of the SQL Statement. It must be unique for each SQL Statement configuration. The SQL Statement isn't a Resource; its monitoring statements are.
- Description
Monitoring Statements tab
Section titled “ Monitoring Statements tab”New 7.13
Click the Monitoring Statements (n) tab to manage the statements this SQL Statement runs. Each monitoring statement has its own accordion; click Add for another one. All of them use the connection of the Authentication tab.

The Monitoring Statements tab: one accordion per monitoring statement, and one Resource for each in the Monitor Views.

Animated walkthrough: on the SQL Statements tab of a SQL Server instance, Add a SQL Statement, enter its connection string, add the monitoring statements Contoso Open Orders and Contoso Failed Orders, and Save. After a reload, both are kept.
- On the SQL Statements tab of the SQL Server instance, click Add and give the SQL Statement a Display Name.
- On the Authentication tab, enter the Connection String.
- On the Monitoring Statements (0) tab, click Add once per monitoring statement and fill in its fields.
- Click Save.
Expand a monitoring statement to edit it:

One monitoring statement. Its Display Name is the Resource name in the Monitor Views.
- Enabled – When checked, this monitoring statement is monitored.
- Display Name – The name of the Resource in the Monitor Views. Required while the monitoring statement is enabled, and unique within the configuration, also across its SQL Statements.
- Description – The user-friendly description of the Resource.
- Command Type – The Type of 'SQL Command', select one of the following:
- Text – For AdHoc TSQL Statements
- Stored Procedure – For existing parameterless stored procedures
- Execute Command – The SQL command(s) to execute. Required for each enabled monitoring statement of an enabled SQL Statement.
An enabled monitoring statement without a Display Name is marked red with Display Name is required, and the configuration isn't saved.

The Display Name is required while the monitoring statement is enabled.
Two monitoring statements with the same Display Name in one configuration stop the save with 400 Configuration Error.

The error names the SQL Server configuration that holds the duplicate.
A SQL Statement from an earlier agent version, with its single command, is migrated once: the command becomes its first monitoring statement.
Stored Procedure
Section titled “ Stored Procedure”Execute one or more stored procedures in the SQL Server database provided by the connection string. For example, enter [YourCustomProcedure] or the full path.
[Database].[dbo].[YourCustomProcedure]Here's an example of stored procedure call using a full path.
User Action Scripts tab
Section titled “ User Action Scripts tab”Add entries in the 'User Action Scripts' tab to allow your end-users to execute scripts on demand. The scripts belong to the SQL Statement: Show Action Scripts on any of its monitoring statements lists them, so a SQL Statement needs at least one enabled monitoring statement for its scripts to show in a Monitor View.

Example of the User Action Scripts tab for on-demand script execution.
A SQL Statement may have any number of scripts.
Click the Add button to add a script.
Then, expand the accordion.

You can then fill out the following properties:
- Enabled – When checked, this SQL Action Script is visible in the end-user list of executable scripts
- Display Name – The user-friendly name of this action script
- Description – User-friendly description for this SQL Action Script
- Command Type – The type of SQL command
- Text
- Stored Procedure
- Execute Command – The SQL command to execute

Example of a script entry for on-demand execution.
Authentication
Section titled “ Authentication”New 6.2.0.0
Each SQL Statement runs with its own connection string, and can impersonate a domain user. All its monitoring statements and User Action Scripts use this one authentication.

The Authentication tab: one connection for every monitoring statement of the SQL Statement.
- Connection String – The connection string used by all monitoring statements of this SQL Statement. Required while the SQL Statement is enabled: the agent refuses to save an enabled SQL Statement without one (requires a connection string). A disabled SQL Statement can be saved without it.

A disabled SQL Statement (ban icon) may have an empty Connection String. - Use Impersonation – Run the statement as the domain user below. Required when the connection string uses Integrated Security; otherwise the agent refuses to save (uses Integrated Security in its connection string. Please enable 'Use Impersonation'...).
- Domain User – The name of the Windows user account. Format: DOMAIN\User
- Password – The password for the provided domain user
You must click 'Save' or 'Save and close' for changes to persist. The new settings/thresholds are evaluated on the next synchronization.

Here's an example of the Save options.
Save and close saves and closes the dialogue.
Close closes the dialogue without saving any changes.
Actions
Section titled “ Actions”The following Remote Actions are available in the Control Center part of the Action menu:

The Control Center part of the Action menu of a monitoring statement.
Details
Section titled “ Details”Click Details in the Action menu. The Details modal shows the Server, Database, and Application of the monitoring statement and an editable Description, with Save; it does not run the statement or show a result.

The Details modal with a Description saved from the Monitor View.
Show Action Scripts
Section titled “ Show Action Scripts”You can execute pre-defined TSQL scripts and immediately see the result. The Nodinite Administrator manages the collection of scripts in the User Action Scripts tab.

Animated walkthrough: open the Action menu of the monitoring statement Contoso Open Orders, click Show Action Scripts, Execute List open orders, confirm, and read the output table.
Click Show Action Scripts in the Action menu. The Action Scripts dialog lists the enabled scripts of the SQL Statement the monitoring statement belongs to, each with an Execute button; every monitoring statement of that SQL Statement offers the same scripts. A script runs with the SQL Statement's connection string.

The Action Scripts dialog of a monitoring statement.
Click Execute on a script and confirm the intent: Execute action? Are you sure you want to execute the SQL script '…'?

Confirmation dialog for script execution.
The result shows under Output from script name, with a Table and a Raw tab, a timestamp, the row count, and the duration.

The result of a script run on demand.
Examples
Section titled “ Examples”There are two ways to provide the outcome (Monitoring state of the Resource) based on the logic in your custom-built SQL Statements:
| # | Text/AdHoc | Stored Procedure |
|---|---|---|
| 1. Select + return code | ❌ Not supported | ✅ Supported |
| 2. Select + throw (raiserror) | ✅ Supported | ✅ Supported |
Use a supported implementation according to the use of either Text/AdHoc or Stored Procedures.
Internally, the Nodinite Database Monitoring Agent executes the Execute Scalar method. Nodinite picks up data from the first column from the first returned row. The extracted value is set as the Log Text unless you raised an exception.
1. Select + return code
Section titled “1. Select + return code”The Log Text presented for the monitoring statement (the Resource) comes from your last SELECT statement (1st row, 1st column). If you do not select anything, the Log Text is empty.
| Return Code | Evaluated State | LogText |
|---|---|---|
| = 0 | OK | From SELECT operation (1st column) |
| < 0 | Error | From SELECT operation (1st column) |
| > 0 | Warning | From SELECT operation (1st column) |
2. Select + throw (raiserror)
Section titled “2. Select + throw (raiserror)”The Log Text presented for the monitoring statement (the Resource) comes from your last SELECT statement (1st row, 1st column) or from the Exception. If you do not select anything, the Log Text is empty.
| Return Code | Evaluated State | LogText |
|---|---|---|
| No exception raised | OK | From SELECT operation (1st column) |
| Throw exception with State = 1 | Error | From exception text |
| Throw exception with State > 1 | Warning | From exception text |
Text Example
Section titled “Text Example”Example of using the SQL Statement with Command Type set to Text. This example counts the rows in the actual table. Depending on your logic, different states can be returned.
DECLARE @rowCount INT, @log VARCHAR(256), @errorLimit INT = 3, @warningLimit INT = 1
SELECT @rowCount = COUNT(1) FROM [ConnectionFailures]
IF (@rowCount > @errorLimit) BEGIN SET @log = 'ERROR Number of connection failures exceeded ' + CAST (@errorLimit AS VARCHAR(18)); THROW 51000, @log, 1; ENDELSE IF (@rowCount > @warningLimit) BEGIN SET @log = 'WARNING number of connection failures exceeded ' + CAST (@warningLimit AS VARCHAR(18)); THROW 51000, @log, 2; ENDELSE BEGIN SELECT 'OK' ENDStored Procedure example
Section titled “Stored Procedure example”Example of using the SQL Statement with Command Type set to Stored Procedure
[SP_CheckConnectionFailures]Example of the Stored Procedure (existing in the actual database):
USE [MyDatabase]GO
SET ANSI_NULLS ONGO
SET QUOTED_IDENTIFIER OFFGO
CREATE PROCEDURE [dbo].[SP_CheckConnectionFailures]AS
BEGIN SET NOCOUNT ON;
DECLARE @rowCount INT, @errorLimit INT = 3, @warningLimit INT = 1, @ret INT = 0, @log VARCHAR(256)
SELECT @rowCount = COUNT(1) from [dbo].[ConnectionFailures]
IF (@rowCount > @errorLimit) BEGIN SET @log = 'ERROR: The number of connection failures was exceeded: ' + CAST (@errorLimit AS VARCHAR(18)); SELECT @log SET @ret = -10 END ELSE IF (@rowCount> @warningLimit) BEGIN SET @log = 'WARNING: The number of connection failures was exceeded: ' + CAST (@warningLimit AS VARCHAR(18)); SELECT @log SET @ret = 10 END ELSE BEGIN SELECT 'OK' END RETURN @ret
END -- ProcedureNext Steps
Section titled “ Next Steps”Related Topics
Section titled “ Related Topics”- Azure SQL Statements
- PostgreSQL SQL Statements
- Database Monitoring Agent
- SQL Categories
- Resources
- Monitoring Agents
- Monitor Views
- PowerShell Monitoring - Similar monitoring approach using custom PowerShell scripts
- Secure Custom Database Scripts and Actions - Centralized guidance for secure SQL statement and action-script execution