sql server logon trigger custom message

Heisenberg 261 Reputation points
2023-03-17T15:49:03.3+00:00

hi folks,

I m creating a logon trigger to restrict any SQL login from a particular host. Following script is working as expected however its not flashing message as mentioned in the RAISERROR. When logon is denied the message user get is "logon failed for login 'xxx' due to trigger execution". Any idea how can i flash custom message?

CREATE TRIGGER [trigger_1] 
ON ALL SERVER
FOR LOGON
AS
BEGIN
	IF
	((
	left(host_name(),5) in ('XXX')
	)
	and 
	 (SELECT name FROM sys.server_principals  WHERE TYPE = 'S' and name = ORIGINAL_LOGIN()) is not null)
	BEGIN
		RAISERROR('Please login using windows authentication, SQL Authentication is refrained from workstation', 25, 1);
		ROLLBACK;
	END
END
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,579 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 109.3K Reputation points MVP
    2023-03-19T22:06:25.1866667+00:00

    Simple answer: You can't.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Zahid Butt 956 Reputation points
    2023-03-17T16:23:50.7433333+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.