Linq to SQL - 双引号问题
我遇到一个问题,如果我在 ASP.NET 中有一个文本区域并在句子的最后输入 2 个双引号,我的 sql 语句中会出现错误。 我已经通过 sql profiler 进行了追踪,但没有成功。
例如。 懒狐狸跳过了狗“”。 这失败了……
”“懒惰的”狐狸跳过了狗。 这看起来不错
欢迎任何指点
I have a problem wherein if I have a text area in ASP.NET and enter 2 double quotes at the very end of the sentence, I get a error in my sql statement. I have traced thru the sql profiler but with no luck.
eg. The lazy fox jump over the dog"". This fails....
""The "lazy" fox jumps over the dog. This seems fine
Any pointers most welcome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能应该发布确切错误消息(如果可能,还应发布说明性代码)。 另请注意,使用 LINQ-to-SQL,您不需要 sql 分析器来查看跟踪:
You should probably post the exact error message (and if possible, illustrative code). Also - note that with LINQ-to-SQL, you don't need the sql profiler to see the trace:
您是否将用户输入直接连接到 SQL 语句中? 如果是这样,那几乎肯定是问题所在。
如果您改用参数化 SQL 语句(即将用户数据作为参数而不是直接在 SQL 中发送),应该没问题。 这样您还可以防范 SQL 注入攻击...
Are you concatenating your user input into the SQL statement directly? If so, that's almost certainly the problem.
If you use a parameterised SQL statement instead (i.e. send the user data as a parameter rather than directly in the SQL) it should be fine. That way you also guard against SQL injection attacks...