Build C# string length validation from SQL Server

If you need a quick and dirty solution to validate string lengths in a .NET model against exact-match columns in SQL Server, you can use this script. This will find all of the varchar and nvarchar columns for a table, and build code to ensure the model doesn’t exceed the max length for any of […]

Catching SQL exceptions in .NET

Here’s one way of handling SQL errors from .NET: For expected errors, like data validation, raise an error with a specific error code and state. Unexpected errors will still blow up with whatever SQL Server’s error message is: In .NET, just check the code and state of the exception – if it matches your custom […]