Generate SqlException with your preferred error code



A quick and dirty way of generating SqlException

class SqlExceptionGenerator
    {
        public static void ThrowException(SqlConnection con)
        {
            con.Open(); // should be a valid connection
            SqlCommand cmd = new SqlCommand("raiserror(50005, 16, 1)", con);
            cmd.ExecuteNonQuery();
        }
    }

Comments

Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

OpenCover code coverage for .Net Core

Using Custom DLL with IronPython / Scripts