I have a small question in my mind.
Suppose I make a big stored procedure in sql server and call this sp from c# application using ado.net.
if sp returns any error or exception now i want to get the actual error with error code in application end.
Please suggest how to do ??
Thanks in advance.
Loading

Munesh SharmaPosted Jul 5, 2014, 2:44 AM
Anupam SinghPosted Jul 5, 2014, 12:56 AM
You can get error codes in SYS.MESSAGES system view (in master db).
and catch it using
try
Ravi ShekharPosted Jul 4, 2014, 7:24 AM
There are multiple types of error and exception we caught in our application.
Is there any built in function in Visual studio to get a proper msg for that error or exceptions which user understand easily.
I can make this type of function but no. of errors and exceptions are very huge.
Then how ??
Ravi
Ravi ShekharPosted Jul 4, 2014, 7:17 AM
Anupam SinghPosted Jul 4, 2014, 6:45 AM
Actually its no need to write any additional code, SqlException class will handle it for you.
Khan Abrar AhmedPosted Jul 4, 2014, 6:37 AM
BEGIN TRY
BEGIN TRANSACTION
--Place the Insert update logice
---
COMMIT TRANSACTION
END TRY
BEGIN CATCH
--Roll back the transaction
ROLLBACK TRANSACTION
--If any error the raise the error
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
RAISERROR (@ErrorMessage,
@ErrorSeverity,
@ErrorState
);
END CATCH