all groups > sql server programming > june 2005 >
You're in the

sql server programming

group:

problem in parameterized queries to avoid Sql Injection



problem in parameterized queries to avoid Sql Injection andy
6/4/2005 4:30:01 PM
sql server programming: I tried to use parameterized queries to avoid Sql Injection attack but in
case I have to generate script based on conditional statement .. things got
out of control ...
The following link wasn't that much helpful...
http://dotnetjunkies.com/WebLog/chris.taylor/archive/2004/10/13/28370.aspx

I basically tried to create @OptionsValue dynamically but it failed...
Can somesone show me how to take care of @p_Options value....since the other
parameters are ok but @p_Options is dynamically joined statement so it's hard
to find solution...

the following is a part out of my proc that got messy and generated
error...specially check @OptionsValue for solution..

If (@inPriceCategoryCode1 IS NOT NULL)
BEGIN
SELECT @Options = N'(PriceCategory = @p_inPriceCategoryCode1 '
SET @OptionsDefinition = N' @p_inPriceCategoryCode1 varchar(4) '
SET @OptionsValue = N' @p_inPriceCategoryCode1 = @inPriceCategoryCode1 '
END

If (@inPriceCategoryCode2 IS NOT NULL)
BEGIN
SELECT @Options = @Options + N' OR PriceCategory =
@p_inPriceCategoryCode2 '
SET @OptionsDefinition = @OptionsDefinition + N', @p_inPriceCategoryCode2
varchar(4) '
SET @OptionsValue = @OptionsValue + N', @p_inPriceCategoryCode2 =
@inPriceCategoryCode2 '
END


EXEC sp_executesql
N'SELECT StrName , PriceTotal
FROM defaultTable
WHERE CompanyCode = @p_inCompanyCode
AND ClassCode = + @p_inClassCode
AND LogoCode = + @p_LogoCode
AND @p_Options,
N'@p_inCompanyCode varchar(4),
@p_ClassCode varchar(10),
@p_LogoCode varchar(5),
@OptionsDefinition ',
@p_inCompanyCode = @inCompanyCode,
@p_inClassCode = @inClassCode,
@p_LogoCode = @LogoCode,
@OptionsValue -- <- this is where I struggle with

This is error msg I got..


Must pass parameter number 8 and subsequent parameters as '@name = value'.
After the form '@name = value' has been used, all subsequent parameters must
Re: problem in parameterized queries to avoid Sql Injection John Bell
6/5/2005 11:48:00 AM
Hi

You may want to check out http://www.sommarskog.se/dyn-search.html

If think your @options should be part of (concatenated to) the statement
and not passed as a parameter. The parameters references in @options should
be passed as parameters.

Posting all DDL would help when answering this question.
http://www.aspfaq.com/etiquett­e.asp?id=5006

John

[quoted text, click to view]

AddThis Social Bookmark Button