How does SQLParameter prevent SQL Injection?

后端 未结 4 1437
借酒劲吻你
借酒劲吻你 2020-11-22 07:59

What exactly is going on in the background that makes it so SQLParameter prevents SQL Inection attacks in a .NET Parameterized query? Is it just stripping out any suspect c

4条回答
  •  爱一瞬间的悲伤
    2020-11-22 08:07

    Basically, when you perform a SQLCommand using SQLParameters, the parameters are never inserted directly into the statement. Instead, a system stored procedure called sp_executesql is called and given the SQL string and the array of parameters.

    When used as such, the parameters are isolated and treated as data, instead of having to be parsed out of the statement (and thus possibly changing it), so what the parameters contain can never be "executed". You'll just get a big fat error that the parameter value is invalid in some way.

提交回复
热议问题