无论您要在“ Auran”记录之后插入的任何数据,都带有单引号/撇号。当您使用字符串串联来构造查询时,这是一个 巨大的
风险,使您容易遭受SQL注入攻击。
将您正在构造的字符串粘贴到SSMS或其他可以向您突出显示SQL语法的工具中,您将看到它。
您在Coding Horror上找到的帖子提供了正确的建议/答案-
使用参数化查询,然后就消失了。出于性能和安全性的考虑,如今通常不建议使用SQL语句的字符串连接。更不用说更容易阅读为源代码了。
$Command = New-Object System.Data.SQLClient.SQLCommand$Command.Connection = $dbConnection$Command.CommandText = "INSERT INTO FileSizeTable (FileName,FileSize,FileNameLength,Date) VALUES (@name,@size,@length,@dt)";$Command.Parameters.Add("@name", $i);$Command.Parameters.Add("@size", $items);$Command.Parameters.Add("@length", $temp);$Command.Parameters.Add("@dt", $currentdate);$Command.ExecuteNonQuery();


