Wednesday, March 21, 2012

Kick all Users?

Is there a T-SQL command to kick all users out of a database while I run an update?

One other thing, and this is probably a network issue, is there any way to pass a message to the users prior to kicking them out, so they can complete what they were doing?

Thanks
Melt

You can use the KILL command. I would recommend that you evaluate doing this as users may also be doing some critical processes. You can issue a NET SEND command to inform them about being disconnected.|||

Hi

A Database statement to kick off all users

USE Master

Go

ALTER DATABASE <DB_Name> SET SINGLE_USER WITH ROLLBACK IMMEDIATE

and when you finished

ALTER DATABASE <DB_Name> SET MULTI_USER WITH ROLLBACK IMMEDIATE

Go

But , this one will give no worning to your users :-(

NB.

|||

Thanks a lot for the replies and the code, I don't have to worry abour my users running critical processes, they're all just "SELECT" users.

How would I send the NET SEND message?

Regards
Melt

|||

if you do that with Enterprise manager it will automatically send

message to the users

|||NET SEND may not be the best & reliable way to do this type of notification. For one, the Windows Messenger service is typically disabled for security reasons on most OS versions. There have been several security vulnerabilities with this service in the past. So you may want to check the latest news on it since NET SEND uses that service. And the state of the service will change from OS version to another and even service pack to another for same OS. Lastly, users can disable it easily. If you don't have to worry that users are running critical processes then the best option might be to just do the operation without notification. If you want to be a nice citizen then you could use a rollback with timeout and then send email to users assuming you have that information in your system (based on windows credentials or sql logins).|||

Thanks everyone for the replies and useful info.

Regards
Melt

No comments:

Post a Comment