Sometimes it happens that there are “ no more licenses available” for Dynamics NAV , from NAV 2013 R2 and next releases, it’s necessary to run the Windows Client or to use Powershell statements to kill some sessions and unlock others. If you are unable to access to NAV (“ no more licenses”), you should need to use SQL Console and kill sessions from there (reading from Active Sessions Table of from sysprocesses View on master db..) “Some user don’t want to use SQL Server to achieve this !” … WARNING : “No more licenses !!” … Immediately Buy Others !!! There are many ways to kill sessions , i list below some methods. With NAV Server Login – C/AL – Powershell Without NAV Server Login – SQL Server Stored Procedures\T-Sql – VB .NET Application Below some methods to kill the sessions even in the case of “ no more licenses available “: SQL Script and VB.NET C/AL Statement to Kill Sessions The Standard Statement for C/AL Code is: STOPSESSION(“Session ID”); Example: IF CONFIRM (‘Kill Session ?’) THEN STOPSESSION(“Session ID”) … GOAL ! …. BUT YOU NEED TO CONNECT TO NAV SERVER ! .. sometimes is NOT possible! ———————————————————- My VB.NET Solution “I wrote a simple solution on VB.NET to Kill Active Sessions using a SQL Connections, you cand find it on GITHUB and TECHNET.” ON GITHUB VB.NET-SQL-Kill-Sessions https://github.com/rstefanetti/NAV_SQL/tree/BV-.NET-SQL-Kill-Sessions ZIP COMPLETE SOLUTION https://github.com/rstefanetti/NAV_SQL/compare/BV-.NET-SQL-Kill-Sessions ON TECHNET Post link https://gallery.technet.microsoft.com/Dynamics-NAV-Kill-SQL-44cbd45a Download link https://gallery.technet.microsoft.com/Dynamics-NAV-Kill-SQL-44cbd45a/file/168079/1/NAV%202017%20Kill%20SQL%20Inactive%20Sessions.zip About My VB.NET Simple Solution, s ome pictures App Config File ———————————————————- SQL KILL STATEMENTS KILL (Transact-SQL) – Syntax for SQL Server, Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse KILL ‘session_id’ [;] Source https://msdn.microsoft.com/it-it/library/ms173730.aspx KEEP IN MIND !!! DON’T KILL PROCESSES IN THIS STATES: -AWAITING COMMAND -CHECKPOINT SLEEP -LAZY WRITER -LOCK MONITOR -SIGNAL HANDLER SOURCE SQL SCRIPTS Source https://www.codeproject.com/Tips/647839/Session-Killer-for-SQL-Server Source https://technet.microsoft.com/en-us/library/ms173730.aspx My Customized release 1) SP_SQL_KillNavServerSession SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO — ============================================= — Description: KILL ALL NAV ACTIVE USER SESSSIONS WITH MULTIPLE INSTANCES — ============================================= CREATE PROCEDURE [dbo].[SP_SQL_KillNavServerSession] AS BEGIN DECLARE @RowIndex AS INT; DECLARE @MaxIndex AS INT; SET @RowIndex = 1; SELECT @MaxIndex = (SELECT top 1 MIN([Session ID]) FROM [ITA].[dbo].[Active Session] WHERE [User ID] = ‘************’ group by [Session ID]) — Remove Active Session DELETE FROM [DB].[dbo].[Active Session] where [Session ID]>@MaxIndex AND [User ID] = ‘*********’ END 2) SP_SQL_KillNONavSession SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON GO — ============================================= — Description: KILL SLEEPING NO NAV SESSIONS — ============================================= CREATE PROCEDURE [dbo].[SP_SQL_KillNoNavSession] AS BEGIN DECLARE @Session TABLE ( id INT IDENTITY(1,1) PRIMARY KEY, [sid] int, ltime DATETIME, hname varchar(MAX), uid varchar(100), lret datetime, etime int ); DECLARE @NotAffectedUserList TABLE ( id INT IDENTITY(1,1) PRIMARY KEY, [uid] varchar(MAX) ); DECLARE @session_time as int; DECLARE @vSID as int; DECLARE @command as varchar(MAX); DECLARE @RowIndex AS INT; DECLARE @MaxIndex AS INT; set @session_time=15; — Assign Session time in Minutes — Assign List of Users who “will not be affected ” by this Session Kill INSERT into @NotAffectedUserList SELECT ‘sa’ INSERT into @NotAffectedUserList SELECT ‘NT AUTHORITY\SERVIZIO DI RETE’ INSERT into @NotAffectedUserList SELECT ‘**************’ INSERT into @NotAffectedUserList SELECT ‘scheduler’ INSERT into @Session SELECT session_id as [Session ID], login_time as [Login Time], host_name as [Host Name], LOGIN_NAME as [Login ID], last_request_end_time as [Last Request End Time], DATEDIFF(minute, last_request_end_time,getdate()) as[Elapsed Time (minutes)] FROM sys.dm_exec_sessions WHERE open_transaction_count = 0 AND host_name <> ‘NAVSRV’ COLLATE Latin1_General_CI_AS AND host_name is not NULL AND DATEDIFF(minute, last_request_end_time,getdate())>=@session_time –AND client_version=4 AND login_name COLLATE Latin1_General_CI_AS not in ( SELECT DISTINCT uid FROM @NotAffectedUserList ) SET @RowIndex = 1; SELECT @MaxIndex = MAX(id) FROM @Session; WHILE( @RowIndex 50 AND loginame <> ‘DIR%’ AND program_name LIKE N’%NAV client%’ AND status=’sleeping’ AND DATEDIFF(mi,last_batch,GETDATE())>=10 AND spid <> @@spid OPEN c_Users FETCH NEXT FROM c_Users INTO @v_spid WHILE (@@FETCH_STATUS=0) BEGIN PRINT ‘Killing ‘+ CONVERT(VARCHAR,@v_spid)+’…’ EXEC(‘KILL ‘+ @v_spid) FETCH NEXT FROM c_Users INTO @v_spid END CLOSE c_Users DEALLOCATE c_Users ———————————————————- OTHERS NICE SOLUTIONS (NAV LOGIN IS REQUIRED) Olof Simren Solution Kill Sessions in Dynamics NAV (from NAV Page) Source https://www.olofsimren.com/kill-sessions-in-dynamics-nav/ Gunnar Solutions ADO NET Solution Kill Idle Connections Source http://www.dynamics.is/?p=471 Poweshell Solution Stopping Idle Microsoft Dynamics NAV Services http://www.softwareanswers.co.uk/software_answers/2015/03/stopping-idle-microsoft-dynamics-nav-services.html Nice Sessions Killing !
↧