Hi all.
I'm getting more adventurous with NPM, and have started investigating the use of SQL in reports. I am comfortable with my knowledge of SQL, but I can do what I need to do and I am by no means an SQL guru! I have found a couple of online documents and sites that have given me enough of an idea to start moving around in the database, so I thought I'd just start with something simple and work up from there.
The problem I am having is getting the report to run in the browser interface. The initial query I have is to help me identify interfaces that I don't want monitored (QoS, Miniport, etc), so I can easily identify them and decide whether to remove them. The query I have is:
select Nodes.NodeID, Nodes.SysName, Interfaces.InterfaceName, Interfaces.InterfaceID
from Nodes
join Interfaces on Nodes.NodeID = Interfaces.NodeID
where Interfaces.InterfaceName like '%Miniport%' or
Interfaces.InterfaceName like '%QoS%' or
Interfaces.InterfaceName like '%WFP%' or
Interfaces.InterfaceName like '%river%'
order by Nodes.SysName
This code works when previewing the report in Report Viewer and in MS SQL Management Studio, but when I try to view it in the browser interface, I get an error message:
System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at SolarWinds.Orion.Common.SqlHelper.ExecuteReader(SqlCommand command) at SolarWinds.Orion.Web.Reporting.OrionReport.QueryData(String query, String orderBy, String grouping, String filter, Dictionary`2 macroContext) at SolarWinds.Orion.Web.Reporting.ReportRunner.WorkerProc()
Through other SQL queries, I have determined that the browser struggles with queries based on the Nodes table, but only when there is an additional criteria in place (WHERE clauses, ORDER BY commands, etc). For example:
select Nodes.NodeID, Nodes.SysName from Nodes
and
select Interfaces.InterfaceName, Interfaces.InterfaceID
from Interfaces
where Interfaces.InterfaceName like '%Miniport%' or
Interfaces.InterfaceName like '%QoS%' or
Interfaces.InterfaceName like '%WFP%' or
Interfaces.InterfaceName like '%river%'
work in the browser, but
select Nodes.NodeID, Nodes.SysName from Nodes order by Nodes.SysName
does not - same error message as above ... and yes, it is reporting a problem near the keyword 'WHERE'. In all cases, the quesries work fine in MS SQL Management Studio and when previewing the report in the Report Writer.
Has anyone else seen this behaviour, and if so, how did you resolve it? Is there something I should be aware of when SQL is presented through the browser? I am familiar enough with SQL to know there are different flavours around, so if there is an issue with the syntax please let me know!