Hi all,
This is my 1st post here. I need your opinion regarding one scenario. I have a custom search page which searches data from a SQL database table based upon the search criteria submitted by the user in my web site. My site is an asp.net 2.0 web site using SQL Server as database using a 3 tier architecture.
(UI- DomainObject(with get set properties) - BusinessLayer - DataAccessLayer - DataBase)
I am able to see 2 ways to do this :
1st Way :
In the code behind page I am building a search string for the selected criteria and passing it to my stored procedure as a parameter. Below is my stored procedure. My Searchquery comes something like ' [columnname] like ''abc%'''
CREATE PROCEDURE [STOREDPROCNAME]
@SearchString
as varchar(500)AS
declare
@strQuery as varchar(1000)set @strQuery = 'SELECT * FROM [TABLENAME]
WHERE '
+ @SearchString
Execute
(@strQuery)
2nd Way :
I dont want to build my search string in the code behind. I want to set the search values to my domain object and I want to pass an object to my data access layer with getters and setters. Then I want to access the values in my stored procedure as parameters and then build the query logic in the stored procedure and execute.
My project consists of huge number of users and sometimes needs to access data from multiple tables. So I want a best approach with maximum flexibility for the programmer for change requests in the search page and it should have good performance.
Please suggest me which approach is the best approach in the above.
Is there any SQL Query injection threat to my application.
Thanks,
Subbu