The reason Stored Procedures with ADO Commands are better is that they will only execute one sql command, unless they are DESIGNED to to otherwise (i.e. through dynamic queries built with EXEC).
Additionally, input values are restricted at the SQL Server by parameter type and length. This prevents all forms of SQL injection attacks.
If your parameter is a varchar, and someone places SQL content into it, it will simply insert that content into the corresponding column, etc.
If you're doing something like this:
Code:
sql = "SELECT * FROM articles WHERE id = " & Request("id")
You're opening yourself up to someone supplying a Request value of "0; DELETE FROM articles", which would result in
Code:
sql = "SELECT * FROM articles WHERE id = 0; DELETE FROM articles"
Using Stored Procedures, you would have something like this:
Code:
CREATE PROCEDURE getArticles
(
@id INT
)
AS
SELECT * FROM articles WHERE id = @id
GO
it would never even execute, because "0; DELETE FROM articles" is not an int, and wouldn't be accepted by the procedure.
Furthermore, even if @id were a varchar, it would utilize the entire "0; DELETE FROM articles" string for comparison rather than breaking it up into a separate query.
Hope this explains a little better