简体   繁体   中英

How to create NAV user by SQL Query in NAV 2015

I need create a user for NAV 2015 from SQL Server 2012 by query.

Anyone know how to do this?

Thanks in advance.

For Dynamics NAV 2018

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

SELECT NEWID()
SET @USERNAME = 'ServerName\Administrator'
SET @USERSID = NEWID()
SET @USERSIDTXT = CONVERT(VARCHAR(50), @USERSID)
SET @WINDOWSSID = 'YourWindowsSID'

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

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

INSERT INTO [dbo].[Access Control]([User Security ID],[Role ID],[Company Name],[Scope],[App ID]) VALUES (@USERSID,'SUPER','','0','00000000-0000-0000-0000-000000000000')
GO

I have tested it with SQL 2016 + NAV 2018 and works

Here the answer

Get your windows SID by CMD console execute

whoami/user

SQL Query:

USE [YourDatabase]
DECLARE @USERSID uniqueidentifier, @WINDOWSSID nvarchar(119), @USERNAME     
nvarchar(50)
SET @USERNAME   = 'Domain\user'
SET @USERSID    = newid()
SET @WINDOWSSID = 'Your SID'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM