Login trigger SQL SERVER

Good afternoon!

I need to create a logon trigger that blocks some login access via Management Studio.

I need to inform the list of logins that must have access to access SQL Server via Management Studio.

Can someone help me please?

Thank you very much
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterCommented:
So here's a simple version that should do the trick:
CREATE TRIGGER logon_trigger_filter
IF APP_NAME() LIKE 'Microsoft SQL Server Management Studio%' AND LOWER(SYSTEM_USER) IN ('testlogin')

Open in new window

It wouldn't be too difficult to enhance this basic logic so the APP_NAME values and the SYSTEM_USER values can be read from a table that is maintained. I suppose you could also join SYSTEM_USER on the sys.server_role_members table to tie this to a server role based approach. Here's a quick & dirty query that will show all server roles to whom the SYSTEM_USER belongs.
SELECT * FROM [sys].[server_role_members]
INNER JOIN [sys].[server_principals] ON [principal_id] = [role_principal_id]
INNER JOIN [sys].[server_principals] [members] ON [members].[principal_id] = [member_principal_id]
[members].[name] = SYSTEM_USER

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Support_38Author Commented:
Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.