MSSQL Query Issue

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
dbsaust
Posts: 76
Joined: Mon Dec 06, 2010 12:41 am

MSSQL Query Issue

Post by dbsaust »

Hi,

I have set up an MSSQL query against one of our databases, it seems to connect to the DB OK but I get the following error:

"CRITICAL: Could not execute the query."

I've tried to search around this forum for this same error but I haven't located anything specifically the same, the details of my query are:

-H XXX.XXX.XXX.XXX --port 1433 --username XXX --password "XXX" --database XXXXX --query 'SELECT COUNT(*) from XXXXX..bax_taskq (NOLOCK) where status in ('u','p')' --result '0' --warning 2 --critical 5

From the command line I input the following in many different connotations but I always get the same message:

./check_mssql -H XXX.XXX.XXX.XXX -p 1433 -u XXX -P "XXX" -D XXXXX 'SELECT COUNT(*) from XXXXX..bax_taskq' -w 1 -c 5
OK: Connect time=0.095323 seconds.

Is there anything that I am doing wrong maybe? Any advice would be great!

Many thanks
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: MSSQL Query Issue

Post by scottwilkerson »

I believe the use of single quotes in your query are causing the problem

Try changing the query to

Code: Select all

SELECT COUNT(*) from XXXXX..bax_taskq (NOLOCK) where status in ("u","p")
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
dbsaust
Posts: 76
Joined: Mon Dec 06, 2010 12:41 am

Re: MSSQL Query Issue

Post by dbsaust »

Hi Scott,

I removed the where clause just to try and get closer to resolution and double-checked some permissions for the user. This pointed me to the direction of access as no manifestation of quotes around this query would work. It seems that the permissions to access this DB hadn't saved when I originally set it up, so I restored them and then set the query as follows and it tested OK:

--query "SELECT COUNT(*) from XXXXX..bax_taskq (NOLOCK) where status in ('u','p')" --result 0 --warning 2 --critical 5

Apologies for the confusion, access permissions it seems to be!

Many thanks

DB
Locked