Script in disabling and removing connected AX users in Dynamics AX 2009

I have already used below script, but the end users are still connected and can navigate in AX though they were already not in the online users.

=== STEP to Remove AX Online users with the exemption of the following user
UPDATE [SysClientSessions]
SET [Status] = 0
WHERE [USERID] NOT IN (‘admin1’, 'admin2,‘bcxxx’,‘user1’)

This removes all AX online users.

=== STEP to Disable All AX users with the exemption of following user
UPDATE [UserInfo]
SET [Enable] = 0
WHERE [ID] NOT IN (‘admin1’, 'admin2,‘bcxxx’,‘user1’)
AND [NetworkAlias] NOT IN (‘admin1’, 'admin2,‘bcxxx’,‘user1’)

This disable the users to login or to connect.

Your help will be highly appreciated.

Thanks.

After running those script we always experience the AO Server service/s stops especially if there are users connected. We did not experience it when there were no users connected.

Yes, changing such data directly in database sounds extremely dangerous. I’m not very surprised that the AOS decides that it can’t continue with such corrupt data.

So what would be the best script to use for this purpose on disabling and removing connected AX users in AX. I intended to use this on a weekly maintenance, that requires no users connected and must not be able to login during the maintenance. Thanks in advance.

This is what you should be doing.
technet.microsoft.com/…/hh433538.aspx

Yes i know how this works sir, but im asking how will i do it using script in ax 2009 ?

My purpose of this is for the automated maintenance since my client wanted to have their maintenance done on Sundays and removing all those users connected to AX.

You already heard it from Martin, manipulating data directly from SQL will cause inconsistency.
Why cannot you have code(can run in batch) in AX that does the same?

Can you give me the code needed to execute since the one i used is not recommendable.

Try by setting the SysServerSessions.Status = 2, this would be same as reject new clients option.