Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate for a valid SQL string

Tags:

c#

.net

sql

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

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.

like image 442
Kyle Rosendo Avatar asked Oct 15 '22 11:10

Kyle Rosendo


1 Answers

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

after your script.


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.

like image 65
Gabriel McAdams Avatar answered Oct 26 '22 22:10

Gabriel McAdams