How to assign administrator role to a user by SQL script in nopCommerce

In past, some nopCommercer users have accidentally removed administrator role from the main admin account and lost the access to administration section. If you are not a programmers or database admin, it can be quite difficult for you to get back the access to the administrator section without anybody's help.

Today, we will go over the process of assigning administration role to any user via SQL script. 

1) Simply go to your public store and create a new account that you would like to use as an admin

nopcommerce admin


2) Now, connect to the SQL database (of your nopCommerce website)

nopcommerce admin



3) Open the database in SQL Server Management Studio

nopcommerce admin



4) Open the [Customer] table and get the customer ID of the account that you would like to use ad admin like this:

In this case, ID = 24

nopcommerce admin



5) Now, open the query build and run this SQL command to add a new entry for mapping administrator role with your customer ID in table [Customer_CustomerRole_Mapping] like this:

INSERT INTO [dbo].[Customer_CustomerRole_Mapping]
           ([Customer_Id]
           ,[CustomerRole_Id])
     VALUES
           (24,1)


Note: Change the "24" with the your customer ID

nopcommerce admin


6) Now, if we check the table [Customer_CustomerRole_Mapping], we should see our entry

nopcommerce admin



Here is the IDs for all system roles:

nopcommerce admin


Now, you should be able to login to administration section and going into the user account, the "Administrator" role should be checked automatically.

nopcommerce admin

About Author

Written By Lavish Kumar

Based out of New York, USA, Lavish Kumar is a full stack web developer by profession and founder of Striving Programmers, a trusted community for developers that offers a wealth of articles and forums to assist individuals with improving their software development skills.

Leave your comment