c# - 如何修复 CA2100 Review SQL 查询的安全漏洞问题

标签 c# sql-server visual-studio optimization code-analysis

我正在分析我的代码并遇到了这个安全问题:

CA2100 Review SQL queries for security vulnerabilities The query string passed to 'SqlDataAdapter.SqlDataAdapter(string, SqlConnection)' in 'Add_item.loadgrid()' could contain the following variables 'Login.dbName'. If any of these variables could come from user input, consider using a stored procedure or a parameterized SQL query instead of building the query with string concatenations. Login Add_item.cs 64

这是突出显示的代码:

SqlDataAdapter da = new SqlDataAdapter("SELECT Newjob FROM [" + Login.dbName + "].newjob", connection. conn );

最佳答案

这就是通常所说的 SQL 注入(inject)漏洞。您应该使用 sqlParameter 对象,而不是将值连接成一个字符串并将该字符串传递给 SQL Server。

关于c# - 如何修复 CA2100 Review SQL 查询的安全漏洞问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19851722/

相关文章:

c# - 在代码隐藏中从 Repeater 获取值

c# - "Exceeded retry count of 10. Failed."因为 csproj 配置错误

sql - 选择父子记录

sql-server - 查询返回两行

c# - 获取收件箱.Net.Mail C#中的所有电子邮件

c# - LINQ 连接两个表

SQL 先按 0 排序,然后按数字/值降序

c - 如何包含必要的 kernel32.lib、 header - 或在自定义应用程序中使用标准 dll?

visual-studio - TFS 将日志文件发布到 #/198/logs/msbuild/agent-2 时出错

c# - 在 Visual Studio/C# 中编译时强制使用 "this"和 "base"