I read so much about the RASIERROR function and its requirements for creating an exception in .NET, but I still cannot get the exception. Here is an SP snippet:
BEGIN
RAISERROR('This is a custom error message.', 16, 1);
RETURN;
END
And here is the .NET code snippet:
cmd.Connection = conn
cmd.ExecuteNonQuery()
'Close the db connection, and local dispose
conn.Close()
Catch ex As SQLException
Dim msg As String = ex.Message
End Try
So, I think I covered the basics:
- Severity level above 10 (using 16)
- Catching the type of SQLException (although it inherits from Exception, so it doesn't matter, I would have thought
- Using 'ExecuteNonQuery'
- In SQL Enterprise Manager, when I start the stored process directly, I get the error message : "Msg 50000, Level 16, State 1, Line 16 This is a custom error message.
So what am I missing? Any help is appreciated, thanks!