Does passing SQL parameters only in the stored procedure so that SQL injection does not run or type checks must also be performed?
As an example -
ADO.NET Code:
Database DBObject = DataAccess.DAL.GetDataBase(); DbCommand command = DBObject.GetStoredProcCommand("usp_UpdateDatabase"); List<DbParameter> parameters = new List<DbParameter>(); parameters.Add(new SqlParameter("@DbName", txtName.Text)); parameters.Add(new SqlParameter("@DbDesc", txtDesc.Text)); command.Parameters.AddRange(parameters.ToArray()); rowsAffected = DBObject.ExecuteNonQuery(command);
SP:
ALTER PROCEDURE [dbo].[usp_GetSearchResults] -- Add the parameters for the stored procedure here @DbName NVARCHAR(50) = '' ,@DbDesc NVARCHAR(50) = '' AS BEGIN SET NOCOUNT ON; SELECT [RegionName] ,[AppName] FROM [ApplicationComponent] WHERE [DBName] LIKE ('%' + @DbName+ '%') OR [DBDesc] LIKE ('%' + @DbDesc+ '%') END
In the code above, I mentioned any types of parameters or validation logic. Will this still precede SQL injection?
Thanks for the guide!
source share