December 29, 2014 at 4:59 am
Dear,
I have created an after insert trigger on a table. When I click on Save button from a particular client machine it was supposed to throw "You can not issue" message. But the message appears "The definition of object 'triggerName' has changed since it was compiled". I have used the following codes.
DECLARE @IP VARCHAR(15);
select @IP = client_net_address
from sys.dm_exec_connections
where session_id=@@SPID
IF (@IP ='127.0.0.1' )
BEGIN
RAISERROR('You can not issue',16,1);
ROLLBACK
END
I am not getting the issue. Please help me to get out from the loop.
Thanks
Akbar
December 29, 2014 at 5:16 am
Dear Akbar,
have you tried disabling and re-enabling the trigger?
Regards,
Shafat Husain
🙂
And Your Lord Never Forgets...!! (64:19 -- Quran)
December 29, 2014 at 5:20 am
Dear Akbar,
If it didn't solve your issue share the complete code and version of your SQL.
Also have you recently upgraded your SQL Version.
Saw a similar kind of thread on msdn who was having issue after upgrade.
Regards,
Shafat Husain
🙂
And Your Lord Never Forgets...!! (64:19 -- Quran)
December 30, 2014 at 4:07 am
Here is my full trigger. Please help me.
CREATE TRIGGER [dbo].[myTrigger]
ON [dbo].[myTable]
AFTER INSERT
AS
BEGIN
DECLARE @IP VARCHAR(15);
select @IP = client_net_address
from sys.dm_exec_connections
where session_id=@@SPID
IF (@IP = '127.0.0.1' )
BEGIN
RAISERROR('You can not issue',16,1);
ROLLBACK
END
END
December 30, 2014 at 6:33 am
Truly a shot in the dark but I've seen worse. It could be that you need to clear cache on the desktop that you're running the code from.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 30, 2014 at 7:29 am
Quick suggestion, should be enough to get you passed this hurdle
😎
USE tempdb;
GO
SET NOCOUNT ON;
IF OBJECT_ID(N'dbo.myTable') IS NOT NULL DROP TABLE dbo.myTable;
GO
CREATE TABLE dbo.myTable
(
MT_ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY CLUSTERED
,MT_VAL INT NOT NULL
,MD_DT DATETIME NOT NULL DEFAULT (GETDATE())
);
GO
CREATE TRIGGER [dbo].[myTrigger]
ON [dbo].[myTable]
FOR INSERT
AS
BEGIN
IF (SELECT COUNT(*) FROM sys.dm_exec_connections WHERE session_id = @@SPID AND client_net_address IN ('127.0.0.1','<local machine>') ) > 0
BEGIN
RAISERROR('You can not issue',16,1);
ROLLBACK
END
END
GO
INSERT INTO dbo.myTable (MT_VAL) VALUES (1),(2),(3);
GO
SELECT
MT.MT_ID
,MT.MT_VAL
,MT.MD_DT
FROM dbo.myTable MT;
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply