0

如果我在我的程序集中实现这样的方法会被认为是危险的吗?

 public void Execute(string sql)
        {
            using (SqlConnection connection = new SqlConnection("MyConnectionString....."))
            {
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();
                command.ExecuteNonQuery();                
            }
        }
4

1 回答 1

1

如果您传入的 sql 字符串是动态构建的并且包含用户输入的连接,这是很危险的。否则,它通常被认为是不好的做法。存储过程是您最好的选择。

这是关于 SQL 注入的 OWASP 文章

于 2012-09-07T21:05:35.587 回答