I want to send the C# ASP.NET an error if unique key that already exist was tried to insert to the
EmailAddress is a
Am I doing it right or are there other ways to do it ?
Should I return a number for each error and I will catch that number in the C# ASP.NET, for each number I will have a different message to send to the client side ( in SQL -
DECLARE @error INT )?
ALTER PROC [dbo].[SignUp] @emailAddress NVARCHAR(320), @passwordHash VARCHAR(32), AS DECLARE @error VARCHAR(20) BEGIN TRY DECLARE @salt UNIQUEIDENTIFIER=NEWID() INSERT INTO Users ( EmailAddress, PasswordHash,Salt) VALUES (@emailAddress, HASHBYTES('SHA2_256', @passwordHash+CAST(@salt AS NVARCHAR(36))), @salt ) END TRY BEGIN CATCH SET @error = "Email address is already exist" SELECT @error END CATCH SELECT EmailAddress FROM Users END