Groups | Blog | Home
all groups > dotnet ado.net > july 2007 >

dotnet ado.net : How to make Raiserror report to ado.net


Tom Pester
7/12/2007 6:10:44 AM
Hi group,

I have put some validation logic in a trigger and when it doesn't
validate I do a rollback + raiserror.

So for so good but how do I detect this in ADO.NET ?

Is there a way to use raiserror or some othe mechanism to communicate
to ado.net/asp.net that someting went wrong? Currently if I do an
insert and it doesn't validate the ASP.NET site still thinks everyting
is fine.
William (Bill) Vaughn
7/12/2007 10:00:57 AM
InfoMessage Event.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------

[quoted text, click to view]

Jim Rand
7/12/2007 1:58:05 PM
BEGIN TRANSACTION;

-- Authorized rep - can't delete
DECLARE @OfficeCount INT;
SET @OfficeCount = (SELECT COUNT(AgencyNET.Office.OfficeID)
FROM AgencyNET.Office INNER JOIN
AgencyNET.StatusLookup ON
AgencyNET.Office.StatusLookupID = AgencyNET.StatusLookup.StatusLookupID
WHERE (NOT (AgencyNET.StatusLookup.Status IN
('Expelled', 'Terminated')))
AND (AgencyNET.Office.AREndUserID = @EnduserID));
IF @OfficeCount >= 1
BEGIN
RAISERROR ('Business Logic:Authorized Representative: Can''t delete
enduser', 14, 1);
COMMIT TRANSACTION;
RETURN 0;
END;


------------------------------------------------
catch (System.Data.SqlClient.SqlException ex)
{
if (catchAndRefill)
{
if (Regex.Match(ex.Message, "^Business Logic:").Success)
{
MessageBox.Show(ex.Message.Substring(15), "Business Logic
Validation");
Fill(ds, adapterList);
throw new Helpers.CheckDeletesException(ex.Message.Substring(15));
}
else
{
_log.Error("DataAccessLayer.Update: Unexpected exception", ex);
throw new Exception("", ex);
}
}
else
{
_log.Error("DataAccessLayer.Update: Unexpected exception", ex);
throw new Exception("", ex);
}
}

[quoted text, click to view]

AddThis Social Bookmark Button