This post outlines the steps how to debug an issue which is happening in non-development or non-production environments e.g. UAT environment.

1.    RDP to your environment where you want to debug the issue, with this example I am connecting to UAT (Sandbox). 
2.    Connect to SQL server
a.     Get the server name from LCS database accounts
b.    Use to connect to database

3.    Create a new SQL sign-in that the developer can use. This step lets the system administrator maintain the security of the sandbox environment. The developer will have access to one database for only a limited time. Use the following code to create the new SQL sign-in.

CREATE USER devtempuser WITH PASSWORD = 'pass@word1'
EXEC sp_addrolemember 'db_owner', 'devtempuser'

4.    Stop following services in development box
a.     IIS or world wide web publishing service development box
b.    Microsoft Dynamics 365 unified Operations: Batch Management service

5.    Go to J:\AosService\WebRoot\web.config.
6.    Save a copy of the original web.config file, so that you can switch back later. I copied file in the same directory and renamed the web.config to webDev.config and copied one to web.config
7.    Edit the following section in the web.config file.
Before your changes
After your changes

8.    Start IIS or world wide web publishing service
9.    Do not start batch service otherwise your batch jobs of development box will start writing into UAT environment. Be careful with this step!!!
10.  Now, connect to your development box from browser. Oops!!! It does not connect and throw an error. Don’t worry let’s jump into event log and see what’s in there

Okay; so it is an access issue and here is the resolution for it.

11.  Execute the following command against Master database in UAT database server. IP address you get from the event viewer.

exec sp_set_firewall_rule N'PPDEV01', '', ''

12.  Connect to development URL again from browser and this time it works. You can now access UAT database (all legal entities etc.)
13.  Restart or your start your VS in development box and attach to Process w3wp.exe to troubleshoot the issue(s)

Done with your debugging and got the resolution J

14.  Now it is time to remove devtempuser from UAT database, this prevents having the permanent access to the sandbox database. Right-click on the devtempuser user under Sabndoxdatabase | Security | Users and delete it.

15.  Stop IIS.

16.  Revert changes from the web.config file or simply delete the copied one and rename the original one from WebDev to Web.

17.  Start IIS.

18.  Start batch service 

19.  Connect to development environment URL and make sure it is connected to development database.