Tag Archives: Microsoft

Microsoft Dynamics Nav – Either the caller does not have the required permission or the specified path is read-only – Error

Today on Microsoft Dynamics Nav 2013R2, I kept getting the following error, which stumped me for a bit…

Either the caller does not have the required permission or the specified path is read-only.

After much investigation, I found a solution to the problem, delete the following folder and restart the service.

C:\ProgramData\Microsoft\Microsoft Dynamics NAV\71\Server\{Nav Instance Name}\users\default

Upon restarting the service, I was able to connect back to Nav without receiving the error.

Automatic T-SQL Formatting with Microsoft SQL Server Management Studio 2014

Within MySql Workbench, there’s a feature called “Clean Up SQL” which automatically tidies up your SQL and the indentation automatically.

This is a very useful feature, as your messy SQL then becomes nice and neat. Unfortunately with Microsoft SQL Server Management Studio (SSMS), this feature is not standard.

Poor Mans T-SQL Formatter - Format T-SQL CodeLuckily I came across the following open source T-SQL formatter library, complete with an add-in for SSMS which adds this functionality – Poor Mans T-SQL Formatter. This plugin automatically formats your SQL, adding tabs and linebreaks etc in order to make it easy to read.

After installing the product, the following folder needs renaming in order to work with the 2014 version of SSMS:

%SystemDrive%\ProgramData\Microsoft\SQL Server Management Studio\11.0


%SystemDrive%\ProgramData\Microsoft\SQL Server Management Studio\12.0

This is due to the installer. The installer puts the files in the incorrect place for the 2014 version of SQL Management Studio. Once you have renamed the folder and restarted SSMS, it will automatically add the options to the Tools menu.
Poor Mans T-SQL Formatter File Changes

Not only does this plugin work for SQL Management Studio, there are also versions for:

If you don’t wish to install the software, there’s an online version available.

Dynamics NAV RTC – Page Slow to Load – Flowfields

With Microsoft Dynamics Nav, it is possible to add a “FlowField” to a table. This flow field is then calculates an aggregate of an underlying table.

Typical uses are to perform the following calculations:

  • Sum
  • Average
  • Min
  • Max
  • Count

Additionally, the following non-aggregate functions are available:

  • Lookup
  • Exists

Typical values which can be calculated via flow fields include:

  • Inventory
  • Quantity on Sales Order
  • Quantity on Purchase Order

With some versions of Microsoft Dynamics Nav, opening a page can be extremely slow. If you compare it to an earlier version, say 2009 or 2013, the speed of the earlier version can be a lot quicker.

This is due to the FlowFields on the page. With some versions of Nav, the FlowFields are calculated when you open the page, which can be quite time consuming, especially where there are lots of records. Even if the FlowField is not visible on the page! On earlier versions of Nav, if you hide the field, the FlowField is not calculated, so the issue is not present.

Therefore if you have a page with a flowfield which is not used, instead of hiding it from the page, delete it completely.

Further information of this issue is available here on the Mibuso forum.

Windows 10 – Blurry Fonts at High Resolutions Due to DPI Scaling

With high resolutions in Windows 10, windows will automatically adjust the DPI of the fonts in order to allow you to see these on the screen.

In most cases, this works, however in some specific applications, it can make the fonts all “blurry” and give you a headache when using the machine.

For example, running the Microsoft Dynamics Nav 2013 R2 Development Environment on a high resolution screen, with DPI scaling set at 250% looks as follows. (Click the image to view full size)

Windows 10 - Display Scaling Enabled

A fix for this is to enable the option “Disable display scaling on high DPI settings” within compatibility mode. This is accessed by right clicking on the shortcut and choosing “Properties”:

Windows 10 - Compatibility Settings

Once ticked and you run the application again, the scaling issue for the text is fixed. Unfortunately in this case, it makes some icons smaller (as you can tell by comparing the screenshots), however it is more usable and does not give you a headache!

Windows 10 - Display Scaling Disabled

Access Microsoft Dynamics Nav 2013 R2 From Windows 10, Not on Domain

Edit: The following updated blog post has a better method for achieving this: Run Programs as a Domain user from a none Domain account.

With Microsoft Dynamics Nav 2013R2, Microsoft recommend using a “Pro” version of windows which is registered on an Active Directory domain.

If you are using a “Home” version of windows, when you try to access Nav via the RTC (Role Tailored Client), you get the following error:

You do not have access to Microsoft Dynamics NAV.
Verify that you have been set up as a valid user in Microsoft Dynamics NAV.

Unfortunately “Home” versions of Windows cannot be registered on a domain (Only Pro and above can be). This error occurs because Nav is trying to use the local credentials from the machine across the domain, which will obviously fail.

In order to solve this issue, edit the following file:

%appdata%\Microsoft\Microsoft Dynamics NAV\71\ClientUserSettings.config

Amend the following line:

<add key="ClientServicesCredentialType" value="Windows" />

To the following:

<add key="ClientServicesCredentialType" value="UserName" />

This then will prompt the following credential prompt – once the correct credentials have been provided, you will be able to access Nav from your “Home” edition of windows.

Prompting for Credentials

In order to access Nav via the Development Environment, the answer is quite simple… Just use the Database Server Authentication:

Development Environment Authentication

Estimate Completion Time For Long Running SQL Query

With Microsoft SQL Server, sometimes there can be long running SQL Queries which you would like to get an estimated ETA from.

Tim Ford has wrote a brilliant article which will provide an ETA for the following types of queries:

  • Database Backup
    • BACKUP
  • Database Restore
  • Index Reorganisation
  • DBCC Operations, such as:
  • Rollback Operations

Running the following SQL query will give the following information for all transactions which are awaiting completion:

  • Session ID
  • Percentage Complete
  • Time Elapsed in Seconds
  • Wait Type
  • Wait Time
  • Last Wait Type
  • Estimated Completion Time
  • SQL Transaction Text
  • SQL Statement Currently Executing
SELECT R.session_id, 
R.total_elapsed_time/1000 AS elapsed_secs, 
DATEADD(s,100/((R.percent_complete)/ (R.total_elapsed_time/1000)), R.start_time) estim_completion_time,
SUBSTRING(ST.text, R.statement_start_offset / 2, 
 CASE WHEN R.statement_end_offset = -1 THEN DATALENGTH(ST.text)
 ELSE R.statement_end_offset
 END - R.statement_start_offset 
 ) / 2
) AS statement_executing
FROM sys.dm_exec_requests R
CROSS APPLY sys.dm_exec_sql_text(R.sql_handle) ST
WHERE R.percent_complete > 0
AND R.session_id <> @@spid

Azure AD Connect – Force Sync Via Command Line

Azure AD connect is a new tool which replaces DirSync for syncing Active Directory information to Azure from the local active directory.

Synchronisation automatically works in the background, but sometimes you want to push through a synchronisation for some reason or another (rather than waiting for the next time it runs). This can be done by running the following 2 commands from the C:\Program Files\Microsoft Azure AD Sync\bin directory:

DirectorySyncClientCmd.exe initial
DirectorySyncClientCmd.exe delta
  • initial – this forces a full sync
  • delta – this forces a delta sync

Azure AD Connect Command Line

Status can be checked by running “Synchronisation Service” and checking the log. In the example below, 452 entries where unchanged and 1 was deleted as part of the forced sync.
Azure AD Connect Synronisation Service Log

Drop All Triggers from MS SQL Database

Recently I’ve had the scenario where I’ve had to drop all SQL Triggers from a Microsoft SQL database.

This could be done manually through the SQL Management Studio, but with a database with lots of triggers can be time consuming to do this.

The following SQL when ran against the database will drop all triggers from the said database automatically:

 USE [{database Name}]
DECLARE @SQLCmd nvarchar(1000)
DECLARE @Trig sysname
DECLARE @owner sysname
DECLARE @uid int

SELECT name, uid FROM sysobjects WHERE type = 'TR'

SET @SQLCmd = N'DROP TRIGGER [' + user_name(@uid) + '].[' + @Trig + ']'
EXEC sp_executesql @SQLCmd

FETCH next FROM TGCursor INTO @Trig, @uid


Orphaned Windows Logins on SQL Server

Recently I’ve had to restore a SQL 2012 backup from a production machine to a test machine. Unfortunately as part of that restore process, logins to the database where not created.

As these users where “Orphaned” i.e. existed in the database, but not in the server, users where not able to login. These can be created manually, however is slow and time consuming where there are multiple users.

The following SQL (from Ted Krueger’s article) automatically created all the logins. The code works in SQL 2005, 2008, 2008 R2 and 2012. It may work in 2014 and 2016, however this is not tested.

USE AdventureWorks
DECLARE @sqlcmd NVARCHAR(500) = ''
IF OBJECT_ID('tempdb..#Orphaned') IS NOT NULL 
  DROP TABLE #orphaned
CREATE TABLE #Orphaned (UserName sysname,IDENT INT IDENTITY(1,1))
INSERT INTO #Orphaned (UserName)
SELECT [name] FROM sys.database_principals WHERE [type] IN ('U','S') AND is_fixed_role = 0 AND [Name] NOT IN ('dbo','guest','sys','INFORMATION_SCHEMA')
IF(SELECT COUNT(*) FROM #Orphaned) > 0
 SET @loop = 1
 WHILE @loop < = (SELECT MAX(IDENT) FROM #Orphaned)
    SET @USER = (SELECT UserName FROM #Orphaned WHERE IDENT = @loop)
    IF(SELECT COUNT(*) FROM sys.server_principals WHERE [Name] = @USER) <= 0
        IF EXISTS(SELECT 1 FROM sys.database_principals WHERE [Name] = @USER AND type_desc = 'WINDOWS_USER')
            SET @sqlcmd = 'CREATE LOGIN [' + @USER + '] FROM WINDOWS'
            PRINT @sqlcmd
        IF EXISTS(SELECT 1 FROM sys.database_principals WHERE [Name] = @USER AND type_desc = 'SQL_USER')
            SET @sqlcmd = 'CREATE LOGIN [' + @USER + '] WITH PASSWORD = N''password'''
            PRINT @sqlcmd
    SET @sqlcmd = 'ALTER USER [' + @USER + '] WITH LOGIN = [' + @USER + ']'
    PRINT @USER + ' link to DB user reset';
    SET @loop = @loop + 1

Automating Reports from Microsoft Dynamics Nav using ETL Tools

Recently I’ve been looking into a piece of software called ETL-Tools – Advanced ETL Processor Enterprise.

This software is designed to perform ETL operations, similar in which to Taskcentre does.

The software is quite well priced, with a single user licence being between $340 and $690 (£216 and £440). This is a purchase cost and includes a years worth of support. Annual maintenance is 20%, but is optional. A site licence is also available which allows unlimited users.

In this blog post, I’m going to cover creating an automated task to generate a PDF document with the sales totals for company, split by salesperson code. The report is designed to run daily and is sent to the sales manager in order to view the progress.

This is using the Nav demonstration database – Cronus, with Nav 2015, running on Server 2012.

Creating Connections
ETL Tools Nav ConnectionFor this task, we’re going to need 2 connections as follows:

  • MS SQL Database – Connection to the Nav Database
  • SMTP – In order to send the email

After opening Advanced ETL Processor, it’s a simple task of right clicking on the blank connections and choosing New. In the screenshot on the right, I’ve shown the Nav connection.

Creating The Report
ETL Tools Report WizardOn right clicking to create the report a wizard is shown. This wizard takes you through a few steps in order to create the basis of the report:

  • Source Connection (In this case, it’s the connection we’ve created earlier)
  • SQL Query
  • Fields to add to the report
  • Groupings
  • Report Orientation
  • Report Layout (Rows or Columns)
  • Theme

After completing the wizard, this opens up in design view for further editing and design:
ETL Tools Report Designer

For this task, I’ve used all default options, plus the following SQL:

   [CRONUS UK Ltd_$Sales Header].[Salesperson Code],
   Sum([CRONUS UK Ltd_$Sales Line].Amount) AS Sum_Amount
   [CRONUS UK Ltd_$Sales Header] Inner Join
   [CRONUS UK Ltd_$Sales Line] On [CRONUS UK Ltd_$Sales Header].[Document Type] =
   [CRONUS UK Ltd_$Sales Line].[Document Type] And
   [CRONUS UK Ltd_$Sales Header].No_ =
   [CRONUS UK Ltd_$Sales Line].[Document No_]
   [CRONUS UK Ltd_$Sales Header].[Document Type] = 1
Group By
   [CRONUS UK Ltd_$Sales Header].[Salesperson Code]

Create Package
After creating the report, we need to create a package to perform the following steps:

  • Run Report
  • Save PDF to Disk
  • Send Email with PDF Attachment

Creating the package is very simple, right click and choose add. We need to drag two “Blocks” onto the planner, “Report” and “Send Email” and join these up together:
ETL Tools Package Design

The screenshots below shows the setup of these two steps:
Run Report
ETL Tools Package Design - Run Report

Send Email
ETL Tools Package Design - Send Email

Running Task
The task can be run by either opening up the Package, right clicking and choosing “Run Package” (F3). Alternatively, under the schedule tab, it can be scheduled to run automatically.

In this example, I’ve set the email to be run manually and sent to my email address. Example in the screenshot below:
ETL Tools Emailed Report

In due course I will do some further investigation into ETL Tools. Watch this space!