| 用参数化查询的方法,如:复制代码using (SqlConnection conn = new SqlConnection(connectionString))
{
    conn.Open();
    SqlCommand comm = new SqlCommand();
    comm.Connection = conn;
    comm.CommandText = "select * from Users where UserName=@UserName";
    //传值 username,不指定参数长度
    //查询计划为(@UserName varchar(8))select * from Users where UserName=@UserName
    comm.Parameters.Add(new SqlParameter("@UserName", SqlDbType.VarChar) { Value = "username" });
    comm.ExecuteNonQuery();
}
 1.过滤SQL需要的参数中的敏感字符(注意加入忽略大小写)
 2.禁用数据库服务器的xp_cmdshell存储过程,删除相应用到的dll
 3.屏蔽服务器异常信息
 |