Look Fantastic PT 728X90

Call of Duty: Mobile

How to prevent multiple logins of the same user in NAV?

How to prevent multiple logins of the same user in NAV?

After exhaust search in the web, find one piece of code to resolve this problem, but I need make modification to optimize the 
Before you work in the sql code, need add one column in the table “User Setup” with the name “Max_ Logins” of type int.
Now, open SQL Management Studio, create new blank query and copyfunctionality of the code.

You can find the original code here

USE [master]
GO
GRANT VIEW SERVER STATE TO PUBLIC
GO

USE [your_db_here]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[sp_$ndo$loginproc]
@appname varchar(64) = NULL,
@appversion varchar(16) = NULL
as
begin
declare @login_count int
declare @max_logins int
declare @sysuser varchar(50)
declare @len int
SET @sysuser = upper(suser_name())
SET @len = LEN(@sysuser)
–attention, I use substring in the suser_name to remove the name of my domain, all my users authenticate with Active Directory Users!!!
select @max_logins = [Max_ Logins] from [dbo].[your_business_here$User Setup] where [User ID] = SUBSTRING(upper(suser_name()),12,@len)
–SET @max_logins = 1;
if exists(select ses.[login_name] from sys.dm_exec_sessions (nolock) ses
left join master..sysprocesses (nolock) pro on pro.[spid] =  ses.[session_id]
where ses.[program_name] in (
‘Microsoft Business Solutions-Navision client’,
‘Microsoft Dynamics NAV Server’,
‘Microsoft Dynamics NAV Server (32 bits)’,
‘Microsoft Dynamics NAV client’,
‘Microsoft Dynamics NAV RTC’,
‘Microsoft Dynamics NAV Classic client’,
Microsoft.Dynamics.Nav.Client’)
and pro.[dbid] = db_id()
and upper(ses.[login_name]) = upper(suser_name())
group by ses.[login_name]
having count(*) > @max_logins
) begin
select @login_count = count(*) – 1 from sys.dm_exec_sessions (nolock) ses left join master..sysprocesses (nolock) pro on pro.[spid] =  ses.[session_id]
where ses.[program_name] in (
‘Microsoft Business Solutions-Navision client’,
‘Microsoft Dynamics NAV Server’,
‘Microsoft Dynamics NAV Server (32 bits)’,
‘Microsoft Dynamics NAV client’,
‘Microsoft Dynamics NAV RTC’,
‘Microsoft Dynamics NAV Classic client’,
Microsoft.Dynamics.Nav.Client’)
and pro.[dbid] = db_id()
and upper(ses.[login_name]) = upper(suser_name())
group by ses.[login_name]
having count(*) > @max_logins
raiserror (‘%s You are already logged on %i time(s) to the system. Access is denied. Contact your System-Administrator.’, 18, 1, @sysuser,@login_count)
return
end
end
GO

Comentarios

Entradas populares