So I have a stored procedure that does the following (modified out the data params):
ALTER TABLE dbo.ReceiptInfo NOCHECK CONSTRAINT Credits_ReceiptInfo_FK1;
UPDATE ReceiptInfo SET CreditAccount=@CreditAccount WHERE CreditAccount=@OriginalAccount;
ALTER TABLE dbo.ReceiptInfo CHECK CONSTRAINT Credits_ReceiptInfo_FK1;
This is all in a stored procedure, which runs perfectly fine when I execute it from management studio but skips the alter constraints when called from ASP.net. I know it’s at least executing the stored proc, because I get a message saying the update conflicted with the constraint.
For the record, I know this could all be solved by ON UPDATE CASCADE, but that option was rejected by upper management.
When you use Management Studio to execute a stored procedure, that is done under your account that presumably has admin rights.
When you execute the sp from asp.net, you probably use another account, that is not allowed to do this.