I am looking for a query validator in c#, which allows me to parse the SQL Text from textbox and verify wether its correct or not before sending it for execution. (MS SQL or DB2 queries).
相关问题
- Sorting 3 numbers without branching [closed]
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Graphics.DrawImage() - Throws out of memory except
- Difference between Types.INTEGER and Types.NULL in
If you would like to validate/parse just a SELECT statement, regardless of how "heavy-duty" that select statement is, I found out that the best and fastest way to validate a select statement is the following: - in your code create 2 select statements (strings) such as:
1) Your valid select statement:
SELECT * FROM HUGE_TABLE JOIN MULTIPLE_TABLES WHERE <<Condition>>
2) Create a similar select statement such asSELECT TOP 1 * FROM HUGE_TABLE JOIN MULTIPLE_TABLES WHERE <<Condition>>
- Parse/Validate just the second one, regardless of how many joins you have in there, it will parse it in milliseconds, such as:Hope it helps! Cheers!
Set your query to sql with this hint:
It just checks your query and returns, like this:
Returns no exception.
While
returns
I think this is what you are looking for. http://www.codeproject.com/KB/database/sqlvalidator.aspx
If you want to validate SQL syntax without the use of a database, the
TSql100Parser
class will do well for this situation.Disclaimer, code borrowed from this post here Code to validate SQL Scripts
Pretty straightforward to use though. If it returns null, then there were no errors in parsing it.