Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


LOGON TRIGGER HELP


LOGON TRIGGER HELP

Author
Message
jarrants
jarrants
SSC-Enthusiastic
SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)

Group: General Forum Members
Points: 144 Visits: 215
Here is the LOGON Trigger that I have in place, whenever I log into the system, I get the error "Logon failed for login 'arrants' due to trigger execution". I'm not doing anything in the trigger other than logging the connection and the application that was used to connect (as you can see in the code below). Any help or ideas that could point me in the right direction on why I keep getting that error message would be appreciated.

Create TRIGGER [DR_AUDIT_LOGON_TRIGGER]
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN

declare
@xml XML,
@PostTime datetime,
@ServerName varchar(255),
@LoginName varchar(255),
@LoginType varchar(255),
@ClientHost varchar(255),
@app_name varchar(255)


set @xml = EVENTDATA()
set @PostTime = convert(datetime, CONVERT(varchar, @xml.query('data(/EVENT_INSTANCE/PostTime)')))
set @ServerName = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/ServerName)'))
set @LoginName = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/LoginName)'))
set @LoginType = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/LoginType)'))
set @ClientHost = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/ClientHost)'))
set @app_name = app_name()

insert into [ARRANTS].dbo.LOGON_AUDIT
(Server_Name, Login_Name, [Login_Type], Client_Host, Application_Name, Post_Time, Event_XML)
select
@ServerName, @LoginName, @LoginType, @ClientHost, @app_name, @PostTime, @xml

/*
CREATE TABLE [ARRANTS].[dbo].[LOGON_AUDIT](
[Audit_ID] [int] IDENTITY(1,1) NOT NULL,
[Server_Name] [varchar](255) NOT NULL,
[Login_Name] [varchar](255) NOT NULL,
[Login_Type] [varchar](255) NOT NULL,
[Client_Host] [varchar](255) NOT NULL,
[Application_Name] [varchar](255) NOT NULL,
[Post_Time] [datetime] NOT NULL DEFAULT (getdate()),
[Event_XML] [xml] NOT NULL
)

*/

END

Thanks,

Jeff
GilaMonster
GilaMonster
SSC Guru
SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)

Group: General Forum Members
Points: 57391 Visits: 44707
Check the SQL error log. Any errors or prints from a logon trigger go in there.

I would suggest wrapping the code in a TRY.. CATCH block and have the catch print out the error message.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


jarrants
jarrants
SSC-Enthusiastic
SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)

Group: General Forum Members
Points: 144 Visits: 215
Thanks Gail, that pointed me in the right direction. Here is the result...

Error message in SQL Error Log:
SELECT failed because the following SET options have incorrect settings: 'ANSI_NULLS, QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods.

The problem was when I created the log table I didn't use the SET ANSI_NULLS ON, SET QUOTED_IDENTIFIER ON options, even though I had tried including the options in the trigger itself.

----------------------------------------------------------------------------
----------------------------------------------------------------------------

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON

drop table [ARRANTS].[dbo].[LOGON_AUDIT]

CREATE TABLE [ARRANTS].[dbo].[LOGON_AUDIT](
[Audit_ID] [int] IDENTITY(1,1) NOT NULL,
[Server_Name] [varchar](255) NULL,
[Login_Name] [varchar](255) NULL,
[Login_Type] [varchar](255) NULL,
[Client_Host] [varchar](255) NULL,
[Application_Name] [varchar](255) NULL,
[Post_Time] [datetime] NULL DEFAULT (getdate()),
[Event_XML] [xml] NULL
)

select * from [ARRANTS].[dbo].[LOGON_AUDIT]

----------------------------------------------------------------------------
----------------------------------------------------------------------------

Create TRIGGER [DR_AUDIT_LOGON_TRIGGER]
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN

SET NOCOUNT ON
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON

declare
@xml XML,
@PostTime datetime,
@ServerName varchar(255),
@LoginName varchar(255),
@LoginType varchar(255),
@ClientHost varchar(255),
@app_name varchar(255)

begin try

set @xml = EVENTDATA()
set @PostTime = convert(datetime, CONVERT(varchar, @xml.query('data(/EVENT_INSTANCE/PostTime)')))
set @ServerName = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/ServerName)'))
set @LoginName = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/LoginName)'))
set @LoginType = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/LoginType)'))
set @ClientHost = CONVERT(varchar(255), @xml.query('data(/EVENT_INSTANCE/ClientHost)'))
set @app_name = app_name()

insert into [ARRANTS].dbo.LOGON_AUDIT
(Server_Name, Login_Name, [Login_Type], Client_Host, Application_Name, Post_Time, Event_XML)
select
@ServerName, @LoginName, @LoginType, @ClientHost, @app_name, @PostTime, @xml

end try

begin catch

print 'Error Message: ' + ERROR_MESSAGE()

end catch

END
GilaMonster
GilaMonster
SSC Guru
SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)SSC Guru (57K reputation)

Group: General Forum Members
Points: 57391 Visits: 44707
Is it all sorted out now?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


jarrants
jarrants
SSC-Enthusiastic
SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)SSC-Enthusiastic (144 reputation)

Group: General Forum Members
Points: 144 Visits: 215
Yes, again thank you for the push in the right direction.
koray_cosar2
koray_cosar2
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 49
Dear All;

I am trying to use same script on my project. is there any connection limitation for logon trigger? Because some users (for example after 10-15 minutes)
they are getting error screen like 'connection problem' from their application screens. if so, how can i increase the connection limits?

thanks in advance
best regards,

Kori...
koray_cosar2
koray_cosar2
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 49
i forget the script. My script was like this:

Create TRIGGER [LOGON_TRIGGER]
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN

SET NOCOUNT ON
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON

IF ORIGINAL_LOGIN()= 'odbc' AND
CONNECTIONPROPERTY('client_net_address') not in (select client_net_address from net_address_pool)
rollback
END
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search