1

Problem: I have an Application (in C#) that uses a regex from a SQL Table Column to check certain things. The details of that don't really matter for the question.

The thing is: "Key" users can make entries to that table (not through the Application but directly :( ). Now it happens from time to time, that they mess up regex syntax which leads to the Application to fail and I cannot change code of the Application.

What I thought of was: maybe there is a way to have MS SQL server check Regex syntax on insert and fail the insert if incorrect.

All search results I found deal with how to use regex in TSQL for SELECT etc. But that is not what I need. I just want the regex's syntax be checked and fail the insert if it is incorrect. Also the semantics of the regex is irrelevant. I just want the program to not fail with an exception. If the regex does not do what the user expects, then that's a different story.

Has anybody done this before or has an idea how this could be done? "That's impossible" would also be an appreciated answer, so I don't have to look any further and can turn to other approaches.

1
  • This may be more work than you're willing to deal with and I don't really have the means to test this out, but it sounds like you 'might' be able to solve this with an INSTEAD OF trigger that invokes a SQLCLR function which receives the REGEX expression as a string and 'tests' it - the function could return a BIT indicating success or failure and the INSTEAD OF trigger could act accordingly to either continue with the INSERT or fail. Commented Feb 21, 2017 at 12:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.