Status Code 401 error on executing SXA commands - DailySitecore

"Status Code: 401" error on sxa r cmd
Image: "Status Code: 401" error on sxa r cmd

In Sitecore SXA, for theme building, JS & CSS magnification we use "sxa r" command from theme folder. 

Challenge:

Due to some reasons, I was not able to complete the operation and I was getting "Status code: 401 Answer" error continuously on the terminal as shown in above image. I re-verified the credentials but it won't worked. Also I was not able to login to Sitecore. 

After doing some research I found it was blocking the theme to deploy into the Sitecore because Sitecore login was failing. It happens when the login get blocked due to multiple failed login attempts (FailedPasswordAttempt). This is Sitecore Locked situation.

Solution:

Here, we need to unlock the Sitecore login. Lets see how to unlock Sitecore login.

Unlock Sitecore user account:

Scenario 1: If you have direct access to MSSQL server

Select Core database: Run the below SQL command

UPDATE  [aspnet_Membership]
SET     IsLockedOut = 0, 
        FailedPasswordAttemptCount = 0
WHERE   UserId IN (SELECT UserId FROM [aspnet_Users] WHERE UserName = 'sitecore\Admin')

This will reset the IsLockedOut and FailedPaswordAttemptCount & you will be able to login with the respective account and try hitting "sxa r" command again it will work.

SQL command to reset Sitecore User Lock
Image: SQL command to reset Sitecore User Lock

Scenario 2: Unlock Sitecore user account in Docker.

In my case, my Sitecore instance was running on Docker. So I didn't had direct access to MS SQL. Hence, I opted to replaced the Core database MDF & LDF files with older one I had as backup.

In docker instance, the MDF & LDF file of MS SQL database is located in the data/mssql folder.
eg. YourProjectFolder/docker/data/mssql/

Remember to take backup the mdf & ldf before replacing.

Locate MDF & LDF for MSSQL in Docker
Image: Locate MDF & LDF for MSSQL in Docker

Hope this article was helpful. Please use comment section if you have any suggestions on this.
Happy Learning ! 


Post a Comment

0 Comments