Best practices for installing and configuring Microsoft SQL Server for Microsoft Dynamics NAV


The documentation on Installation Considerations for Microsoft SQL Server and Microsoft Dynamics NAV has been updated with information on recommended settings for SQL Server 2012, 2014, and 2016.

The documentation contains recommendations on topics such as

  • Storage and recommended disk block size
  • Virus scanning
  • Memory
  • TempDB database configuration
  • Auto-growth of database and/or transaction log files
  • Max degree of parallelism (MAXDOP)
  • Trace flags 1117 and 1118 (full extents only and equal growth of all files in a filegroup)
  • Service accounts and instant file initialization (Perform Volume Maintenance Tasks)
  • Statistics (auto-create, auto-update and maintenance jobs)
  • Page Verify
  • Backup and restore

Source: Best practices for installing and configuring Microsoft SQL Server for Microsoft Dynamics NAV

Read more at:
https://msdn.microsoft.com/en-us/dynamics-nav/installation-considerations-for-microsoft-sql-server

Advertisements

“ALL ABOUT” Kill (In)active Sessions when “no more licenses”


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 !!!
license1.png
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
ON TECHNET
Post link
Download link
About My VB.NET Simple Solution, some pictures
kill1
kill-2
kill-3
App Config File
<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name=”NAV_2017_KIll_SQL_Inactive_Sessions.My.MySettings.Demo_Database_NAV__10_0_ConnectionString”
connectionString=”Data Source=STEFANETTILEN\SQL2012ENT;Initial Catalog=&quot;Demo Database NAV (10-0)&quot;;Integrated Security=True”
providerName=”System.Data.SqlClient” />
</connectionStrings>
<startup>
<supportedRuntime version=”v4.0″ sku=”.NETFramework,Version=v4.5″ />
</startup>
</configuration>
———————————————————-
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
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 <= @MaxIndex)
BEGIN
SELECT @vSID = sid
FROM @Session
WHERE id = @RowIndex;
 — String together the KILL statement
SELECT @command = ‘KILL ‘ + CAST(@vSID AS varchar(5))
 BEGIN TRY
  — Execute the final string to KILL the spids
EXEC (@command)
END TRY
BEGIN CATCH
declare @emsg varchar(500);
SELECT
@emsg=ERROR_MESSAGE();
  print @emsg;
END CATCH
 SET @RowIndex = @RowIndex + 1;
END;
END
// KILL SQL INACTIVE SESSIONS FOR NAV APPLICATIONS
// ONLY FOR SLEEPING SESSIONS – OLD NAV CLIENTS
a very Simple SQL Stored Procedure to ‘kill’ sql inactive sessions
idle (sleeping) for 10 minutes related to “Nav Client” applications
*** it’s necessary to identify correct “application name” ***
*** ex: program_name LIKE N’%NAV client% *** or %NAV Web%
DECLARE @v_spid INT
DECLARE c_Users CURSOR
FAST_FORWARD FOR
SELECT SPID
FROM master..sysprocesses (NOLOCK)
WHERE spid>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
Nice Sessions Killing !

“ALL About” How To Boost Dynamics NAV Server


Hi Guys,
another post of “ALL About” Series, in this case, some people have asked me about NAV configuration and how to configure NAV Server for better performance (Boosting
NAV..);  also in Microsoft Forum there are several posts about this topic, i searched and collected a variety of useful information for a correct NAV Server configuration.
Documents and Posts
“Great White Paper” about typical questions around the number of users or tenants, hardware requirements, scaling, and upgrading
-> “…How to have a great configuration and “How-to Boost NAV”!!
“This white paper provides detailed insight into the concepts and principles that support performance testing in Microsoft Dynamics NAV”.
By outlining some sample goals from the start, it explains how you can use load testing to optimize your application and hardware to meet the customer and user requirements – addressing typical questions around the number of users or tenants, hardware requirements, scaling, and upgrading”
Below some useful information about NAV Server Configuration.
NAV Server Configuration Best Practices (from Whitepaper)
1) Number of Microsoft Dynamics NAV Service Tiers
When a client connects to Microsoft Dynamics NAV Server, the load balancer will select a server and keep the connection open throughout the lifetime of the client.
This means that setting up more servers behind a load balancer will increase the capacity of the cluster of Microsoft Dynamics NAV Service tiers.
2) Server Memory
Each Microsoft Dynamics NAV Service tier needs 500Mb of memory to run.
On top of that, the Microsoft Dynamics NAV Service tier needs memory for each active session, even if they are idle.
The more pages the user have opened, the more memory gets allocated, but a good starting point for doing sizing calculations is around 10Mb per active session.
Idle sessions are not terminated if they are running the Windows client.
Server CPU (cores and speed) Faster CPU will get things done faster, and more cores can run more things in parallel.
Idle sessions on the Microsoft Dynamics NAV Service tier don’t use any CPU power, except for generic housekeeping, which shouldn’t be counted.
3) Server CPU (cores and speed)
Faster CPU will get things done faster, and more cores can run more things in parallel.
Idle sessions on the Microsoft Dynamics NAV Service tier don’t use any CPU power, except for generic housekeeping, which shouldn’t be counted.
Active sessions will use CPU power depending on what they do, but it is hard to generalize how much.
For example, CPU power is used whenever the user is performing a task that requires the Microsoft Dynamics NAV Service tier to run some business logic or perform some UI logic or setup server pages.
If the Microsoft Dynamics NAV Service tier does a lot of IO (SQL calls or client callbacks), then the CPU will be waiting for response and thus be loaded less.
4) Data Cache Size
This is a Microsoft Dynamics NAV Server setting, which located in CustomSettings.config file. Sets the data cache size. This is an abstract value with contextual meaning on the type of the item being cached.
<add key=”DataCacheSize” value=”9″ />
The number you specify in DataCacheSize setting determines how much memory is used for caching data.
The actual amount of memory (in MB) allocated is 2n, where n is the value of the DataCacheSize setting:
Value Memor y 9 (default) 512Mb 10 1Gb 11 2Gb 12 4Gb 13 8Gb 14 16Gb 15 32Gb …
When running a single tenant system the default value of 9 is probably good.
When running a multi-tenant system, the data cache is shared between all tenants.
Set to 0 to disable cache.
boost2
5) Metadata Provider Cache Size
This is a Microsoft Dynamics NAV Server setting, which located in CustomSettings.config file.
Sets the Metadata Provider cache size (in number in objects cached).
Set to 0 to disable cache.
<add key=”MetadataProviderCacheSize” value=”150″ />
You can monitor the number of objects in the metadata cache by monitoring the following performance counter on the Microsoft Dynamics NAV Service tier.
There is really NO REASON not to set this to a high value (like 10000) if you are not pressed on memory on the Microsoft Dynamics NAV Server.
6) Max Concurrent Calls
This is a Microsoft Dynamics NAV Server setting, which is located in CustomSettings.config file.
Maximum number of concurrent client calls that can be active on the Microsoft Dynamics NAV Server.
To disable this setting set the value to “MaxValue”.
<add key=”MaxConcurrentCalls” value=”40″ />
The number specified here determines how many concurrent calls the Service Tier is able to handle. The more cores in your server, the higher this value can be.
NAVPERF (On Github)
GitHub organization for performance testing Microsoft Dynamics NAV
GitHub You will find a couple of projects on GitHub, which contains some sample code on how to do performance tests.
The GitHub organization is used to store the sample repositories and is available here:
boost1
boost3
nav-2017-sanmple

Microsoft Dynamics NAV 2017 Load Test sample as references from the Load Test WhitePaper

Enables you to create scenario tests for Microsoft Dynamics NAV.

The solution consists of:

Microsoft.Dynamics.Nav.LoadTest : A sample test for NAV Order Processor Scenarios Microsoft.Dynamics.Nav.TestUtilities : Test utilities to help build test scenarios Microsoft.Dynamics.Nav.UserSession : Client Library for the NAV Client Services Web Service

On the Microsoft Dynamics NAV 2017 DVD, you will find a folder called Test Assemblies. This folder contains one DLL, which is needed for running Load Tests: Microsoft.Dynamics.Framework.UI.Client.dll  The DLL is also included in this project.

Others nice links
Optimizing SQL Server Performance with Microsoft Dynamics NAV
https://msdn.microsoft.com/en-us/dynamics-nav/optimizing-sql-server-performance-with-microsoft-dynamics-nav
Videos
How Do I: Run NAV Performance Tests Using Visual Studio in Microsoft Dynamics NAV
https://www.youtube.com/watch?v=IG-y8DsXqaQ
Some my old posts here:
Monitoring Microsoft Dynamics NAV 2015 Server Using “Performance Counters”
https://robertostefanettinavblog.wordpress.com/2015/07/06/monitoring-microsoft-dynamics-nav-2015-server-using-performance-counters/

SQL Server 2016 is generally available


sql server 2016

Official News from Microsoft’s Information Platform

Best News

  • A new platform for intelligent applications
  • Benchmark leadership through efficient use of modern hardware
  • Large performance improvements from prior versions
  • Unmatched security record
  • Unmatched value proposition
  • Gartner Magic Quadrant for Operational DBMS Leader

Datasheet http://www.microsoft.com/it-it/server-cloud/products/sql-server-2016/

Source: SQL Server 2016 is generally available today

BOOST NAV – How to show most 50 heavy queries on SQL SERVER


query

BOOST NAV – How to show most 50 heavy queries on SQL SERVER

… very nice SQL Script to discover slow Sessions !!

SQL SCRIPT

SELECT TOP 50 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,

((CASE qs.statement_end_offset

WHEN 1 THEN DATALENGTH(qt.TEXT)

ELSE qs.statement_end_offset

END qs.statement_start_offset)/2)+1),

qs.execution_count,

qs.total_logical_reads, qs.last_logical_reads,

qs.total_logical_writes, qs.last_logical_writes,

qs.total_worker_time,

qs.last_worker_time,

qs.total_elapsed_time/1000000 total_elapsed_time_in_S,

qs.last_elapsed_time/1000000 last_elapsed_time_in_S,

qs.last_execution_time,

qp.query_plan

FROM sys.dm_exec_query_stats qs

CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt

CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp

ORDER BY qs.total_logical_reads DESC  /* logical reads */

/* ORDER BY qs.total_logical_writes DESC — logical writes

ORDER BY qs.total_worker_time DESC — CPU time */

 

You are Welcome !

Script Search for a string in “all tables” of SQL Server Database


SQL Script

Good & Fast Script to search for a string in “all tables” of SQL Server Database, very useful with NAV Databases too (to find data FAST in each database\company, no C/AL Code or powershell commands required )

link Script Search for a string in all tables of SQL Server Database  (from MSDN Script Center)

by Sorna Kumar Muthuraj

Great.

SQL Server MAXDOP configuration option for Microsoft Dynamics NAV


SQL Server MAXDOP configuration option for Microsoft Dynamics NAV

My question to NAV Team about suggested configuration  : ‘SET MAXDOP =  ????’  with NAV 2009, 2013, 2015 ????

http://blogs.msdn.com/b/nav/archive/2015/06/03/sql-server-worker-threads-and-microsoft-dynamics-nav.aspx

Configure the max degree of parallelism Server Configuration Option

https://msdn.microsoft.com/en-us/library/ms189094.aspx?f=255&MSPPError=-2147217396

sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
sp_configure 'max degree of parallelism', 1; /*Replace 1 with your preferred MAXDOP value */
GO
RECONFIGURE WITH OVERRIDE;
GO