Is there a good way to parse a SQL statement to ensure it contains only a SELECT statement and nothing else? I am using C#, System.Data.SqlConnection, and MS SQL Server
You should connect to the database as a user that doesn't have permission to do anything other than a SELECT
.
This way, any non-SELECT
statement will be unable to execute.
This is the most secure solution possible, short of duplicating SQL Server's parser.