验证一个有效的SQL字符串 [英] Validate for a valid SQL string

查看:117
本文介绍了验证一个有效的SQL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法(或现有的库,不一定内置到.NET)在C#中,执行简单的SQL字符串验证?

Is there a way (or existing library, not necessarily built into .NET) in C# that performs simple SQL string validation?

场景:建筑update语句,以减少对SQL负载与个别报表的负载。如果字符串构建做了一些奇怪,像一个逗号,例如结束,我希望能够以验证字符串正确。

Scenario: Building update statement to reduce load on SQL load vs. individual statements. In case the string build does something "odd", like ending with a comma for instance, I'd like to be able to validate that the string is correct.

推荐答案

如果你想使用SQL Server验证SQL,您可以通过添加这样做

If you want to validate the SQL using SQL Server, you can do so by adding

SET PARSEONLY ON

你的脚本之前,然后

before your script, and then

SET PARSEONLY OFF

在你的脚本。

如果你需要避免去到数据库,那么也许你可以使用该程序集<一href="http://www.microsoft.com/downloads/details.aspx?FamilyID=BB3AD767-5F69-4DB9-B1C9-8F55759846ED&displaylang=en"相对=nofollow> Microsoft Visual Studio团队系统2008年数据库版GDR 包括(他们有code处理SQL解析和脚本生成)。如果你没有数据库版本或团队套件,你可以下载试用版本,以获得该组件。

If you need to avoid going to the database, then maybe you can use the assemblies that Microsoft Visual Studio Team System 2008 Database Edition GDR includes (they have code that handles SQL parsing and script generation). If you don't have the database edition or team suite, you can download the trial version to get the assemblies.

这里是一个链接我发现如果有人是使用这些程序集。

Here is a link I found where someone is using these assemblies.

这篇关于验证一个有效的SQL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆