【发布时间】:2012-06-01 03:13:00
【问题描述】:
我想知道在ExecuteStoredProcedure执行sql时是否需要使用参数化查询来防止SQL注入攻击?
根据这个MSDN link,我应该使用参数。
根据这个other MSDN link,使用{0}的sql字符串相当于使用参数。
那么在我的 SQL 语句中只包含 {0}、{1} 等真的可以吗:
var rv = _context.ExecuteStoreQuery<int>("select ID from table where typeID = {0}", typeID);
或者我需要:
var param = new SqlParameter("@typeID", SqlDbType.Int);
param.Value = typeID;
var rv = _context.ExecuteStoreQuery<int>("select ID from table where typeID = @typeID", param);
【问题讨论】:
-
您不使用存储过程是否有原因?
标签: entity-framework-4 sql-injection executestorequery