转义 SQL 查询 - 支持 .Net 中的不同数据库平台

发布于 2024-07-23 01:55:52 字数 392 浏览 2 评论 0原文

是否有一个 .Net 项目/dll,支持转义用户提供的输入以进行各种数据库系统的数据库查询?

我希望我们整个团队能够标准化并使用一个模块来执行用户提供的输入的转义,然后将其用于参数化 SQL 查询。

理想情况下,我想在配置文件中指定数据库系统(oracle、SqlServer、mySql 等),并能够调用 Escape(variableName),它会根据 web 中当前的数据库设置转义字符串内容。配置文件。

如果没有,下一个最好的办法就是 EscapeForOracle、EscapeForSqlServer 等。

该项目至少应该支持 Oracle、SqlServer 和 MySql。

我想知道我是否需要在内部创建这个,或者是否存在现有的商业/开源产品来执行此操作。

Is there a .Net project/dll, that supports escaping of user supplied input to database queries for various database systems?

I would like our entire team to standardize and use one module to perform escaping of user supplied input that will then be used in parameterized SQL queries.

Ideally, I would like to specify the database system (oracle, SqlServer, mySql, etc.) in the config file and be able to call Escape(variableName) and it would escape the string contents based on the current database setting in the web.config file.

If not, the next best thing would be something like EscapeForOracle, EscapeForSqlServer, etc.

At a minimum the project should support Oracle, SqlServer and MySql.

I am wondering if I need to create this in-house or if an existing commercial/open-source product exists to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

走过海棠暮 2024-07-30 01:55:52

我认为你不需要这样的东西。

运行参数化查询/存储过程时,请使用参数集合。
指定适当的数据类型、长度、精度和 提供有效值。
转义将由数据库提供者完成。

如果我没有正确理解你的问题,请告诉我。

I don't think you will need such a thing.

When running a parametrized query/stored procedure, use a parameters collection.
Specify appropriate data type, length, precision & supply a valid value.
Escaping will be done by DB provider.

Let me know, if I have not understood your question correctly.

节枝 2024-07-30 01:55:52

在 .NET 中,您可以使用 DbReader 和 DbConnection 等通用类来代替 SqlConnection。 就像 shhkalpesh 和 Lasse V. Karlsen 所说,您可以使用参数,框架或驱动程序将为您处理转义。

但实际上,如果您希望为 Oracle 和 Sql Server 开发产品,那么您所讨论的开销就很大。 正确逃脱只是冰山一角。 如果您还没有安装 Oracle 和 Sql Server 测试服务器,那么您可能还没有开始:)

In .NET, you can use the generic classes like DbReader and DbConnection instead of SqlConnection. Like shahkalpesh and Lasse V. Karlsen said, you can use parameters and the framework or driver will handle the escaping for you.

But practically speaking, if you wish to develop a product for both Oracle and Sql Server, you're talking MAJOR overhead. Escaping correctly is just the tip of the iceberg. If you haven't installed an Oracle and a Sql Server test server, you probably haven't even started :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文