Tuesday, May 27, 2014

NAV 2013 & NAV 2013 R2 - You do not have access to Microsoft Dynamics NAV - Create User From SQL.

Hi all,

This post is based on suggestion from +Ami Paneri Upadhyay

* The Screen Shots and Query Applies - TO NAV 2013 R2. Steps Remain Same for NAV 2013 but query will get change.

* The Query for NAV 2013 can be found in my Skydrive, Link at the end of the post.

Let's see what was required and how we can achieve it.

CASE -

I received a database from customer and my windows login is not there in the database. I don't want to delete Customer Users from the database but want to add myself in the Users. How can we do this?

OR

We have a database internally for development. All the consultants having User ID's in the database are not available. I want to access the database, How can i achieve it?

If you are using NAV 2013 R2 or Higher Please refer this article.



What is the Error message?

Where i try to open the database i get below error from Role Tailored Client -

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



What we Want?

A) Add My Windows Login Details in User Table & User Property Table.
B) Add Role to My User in Access Control Table.

What are the Fields that are required to be filled in?

A) USER TABLE -

Below are the fields in USER TABLE.



The Problem that i see in this field list is of Field "Windows Security ID".

B) USER Property TABLE-

Below are the fields from USER Property Table.



All fields Look Good in this Table.

C)  Access Control Table -

Below are the fields from Access Control Table.



All fields Look Good in this Table.

So let's see How can i get "Windows Security ID" for my ID so that i can add same in User Table.

STEP 1 - HOW TO GET Windows Security ID or SSID

You can find so many ways to find it, but i find the Powershell as easy tool to find it.

1. Open Powershell.

2. Copy Below command in Command Window.
-----------------------------------------------------------
# Author - Saurav Dhyani
# BLOG - saurav-nav.blogspot.com
# Replace YourDomain\Your ID with your Domain Name & User Name

$objUser = New-Object System.Security.Principal.NTAccount("YourDomain\Your ID")

$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
------------------------------------------------------------

Replace YourDomain\Your ID with Your Domain and USER ID.

Run the Command and in the Output Window you can see your SSID, as shown below.



Copy and Save the SSID, we will require it further.

STEP 2 - ENTER USER Details in NAVISION Database with Roles.

1. Open SQL Server Management Studio.

2. In My Case the database that i want to get access is Demo Database NAV (7-1).

3. Click on New Query and paste below listed command in the query window.

------------------------------------------------------------------------
-- Author - Saurav Dhyani
-- BLOG - saurav-nav.blogspot.com
-- APPLIES TO - NAV 2013 R2
-- Replace
-- DATABASE NAME - with your database name
-- YourDomain\Your ID - with your Domain Name & User Name
-- Your SSID - with SSID as copied in STEP 1

USE [DATABASE NAME]

DECLARE @USERSID uniqueidentifier, @WINDOWSSID nvarchar(119), @USERNAME nvarchar(50), @USERSIDTXT varchar(50)

SELECT NEWID()
SET @USERNAME   = 'YourDomain\Your ID'
SET @USERSID    = NEWID()
SET @USERSIDTXT = CONVERT(VARCHAR(50), @USERSID)
SET @WINDOWSSID = 'Your SSID'

INSERT INTO [dbo].[User]
          ([User Security ID],[User Name],[Full Name],[State],[Expiry Date],[Windows Security ID],[Change Password],[License Type]
          ,[Authentication Email])
    VALUES
          (@USERSID,@USERNAME,'',0,'1753-01-01 00:00:00.000',@WINDOWSSID,0,0,'')

INSERT INTO [dbo].[User Property]
          ([User Security ID],[Password],[Name Identifier],[Authentication Key],[WebServices Key],[WebServices Key Expiry Date],
          [Authentication Object ID])
    VALUES
          (@USERSID,'','','','','1753-01-01 00:00:00.000','')

INSERT INTO [dbo].[Access Control]
          ([User Security ID],[Role ID],[Company Name])
    VALUES
          (@USERSID,'SUPER','')
GO
------------------------------------------------------------------------
Replace

DATABASE NAME - with your database name
YourDomain\Your ID - with your Domain Name & User Name
Your SSID - with SSID as copied in STEP 1

Execute the Query and result we be something like as shown below.



Now if i try to Run the windows client i will be able to access same.

* The Query provide SUPER Role to user, if required you can change the Role in the Last part of the query.

THE Power shell command & SQL Queries can be downloaded from my SKYDRIVE.

File Names in Sky Drive - NAV 2013 & NAV 2013 R2 Add User to Database.rar

The Zip Folder Contain Below Listed Files -

-- Power Shell Command  - (Applies to NAV 2013 & NAV 2013 R2)
-- SQL Query - (Applies to NAV 2013)
-- SQL Query - (Applies to NAV 2013 R2)

Your Commands and feedback are much appreciated.

Thanks & Regards,
Saurav Dhyani
saurav-nav.blogspot.com