i have tried with the above code.i am getting the reslut.
but still it is showing sql injection.
why what is the wrong in this code.
CEHJ
No - that's still set-based. Try to append ORs (or equals)
ste5an
Nothing, the scanner is too sensitive.
But you should extract the query string building to a separate method, use only a parameter (int) for the number of required placeholders, use string consts to build it.
Maybe the scanner does detect this correctly. But when not, you can simply verify, that you now don't have SQL injection. And maybe you can annotated exceptions for the scanner in code.
I have refreshed IDE and tried one more time the above code resolves the injection.sql issue
srikotesh
ASKER
Hi ste5an,
can you please elaborate more using an ad-hoc query way,
I still didn't understand how to pass the input values to--@AN01,@AN02...
ste5an
Well, the indicator for SQL injection is string concatenation with parameters or variables. Thus you need a (constant) literal. This means that you must specify the entire SQL statement including all possible parameters with their name (which is inefficient when you need large numbers of parameters).
Thus my sample has ten hardcoded parameters, which must be filled before you execute it. While you're limited to 10 parameters, you still need to ensure that it also works for e.g. only one parameter. This simple means, that you assign the first value to all parameters, which you don't need. As the WHERE predicate uses OR to concatenate them, this redundant, but it makes your SQL statement for sure SQL-injection-proof