Does passing SQL Parameters to a stored procedure alone ensure that SQL injection won't happen or the type checks also need to 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 above code, I havent mentioned any parameter types or validation logic. Would it still preevnt SQL injection?
Thanks for the guidance!