Question

I want to set up a server while multiple users could login at the same time, as long as they are not the "same user".

How could I set it up so when the user with the account username "Bob" login again, whether it's from the same computer or another, the old connection will be terminated?

Thanks for your help.

Much appreciated!

Edit:

"Bob" is a Database user account, the "User ID" in the "Connection String", I'm sorry I don't really know what it is called.

Was it helpful?

Solution

You probably want to use a Logon Trigger to manage this. This specific part of the docs linked above mentions how you can limit the number of sessions for a specific Login:

You can use logon triggers to audit and control server sessions, such as by tracking login activity, restricting logins to SQL Server, or limiting the number of sessions for a specific login.

The first example in the docs is close to what you want, except it'll rollback the newer logins. If you want to kill the older logins you can use the login_time column of sys.dm_exec_sessions and kill the older sessions for that specific login_name.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top