Page 1 of 1

Check_mssql and linked server queries

Posted: Tue Sep 03, 2019 3:14 pm
by dietdrpepper
Hello everyone. Last week, we came up with a few queries that we wanted to use to monitor if replication is starting to go bad, but when we tried to use a linked server query or a view with check_mssql, the error that came back was:

string(144) "select count(*) from farad_production..control_systems s1 left join srvdbdwp01.scwdw.dbo.control_systems s2 on s1.id = s2.id where s2.id is null"
CRITICAL: Could not execute the Query.

I started to then poke around the check_mssql code and see if I could figure out what PDO was having an issue with:
// Attempt to execute the query/stored procedure $time_start = microtime(true); $pdo_query = $connection->prepare($query); if (!$pdo_query->execute()) { var_dump($query); $exit_code = 2; $output_msg = "CRITICAL: Could not execute the $querytype.\n"; display_output($exit_code, $output_msg); } else { $time_end = microtime(true); $query_duration = round(($time_end - $time_start), 6); $output_msg = "$querytype duration=$query_duration seconds."; }

That's as far I was able to get, PHP and I do not get along together and I broke our server because of it (I reverted the bad code to unbreak). Thoughts?

Re: Check_mssql and linked server queries

Posted: Wed Sep 04, 2019 9:21 am
by mbellerue
I'm digging into this on my side, but I just wanted to throw out a quick question.
farad_production..control_systems
Should that be farad_production..control_systems? I'm not used to seeing two .'s next to each other. Does this query work if you copy/paste it into Management Studio?

Re: Check_mssql and linked server queries

Posted: Wed Sep 04, 2019 9:24 am
by dietdrpepper
Correct, it's an older version of sql syntax. It also does run. I wonder if that is why PDO isn't liking it? There's a few here that also use the older join syntax which kills me and wants to rewrite queries, lol.

join on table 1.id = table 2.id,
table 3,
table 4

Ugh.

Re: Check_mssql and linked server queries

Posted: Wed Sep 04, 2019 9:57 am
by mbellerue
It could be that PDO doesn't like the older syntax. Is it possible to re-build that query and try it out?