Earlier versions of AX offered information about the SPID from within AX and the Online Users form. In AX 2012 it is a bit more tricky and requires a little tweaking of the AOS configuration.
What you need to do is to add a key in the registration database and it goes like this:
1. Run regedit.exe
2. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dynamics Server\6.0\<ServerNumber>\<MyConfigurationName>. If you have not changed the configuration of the AOS it is named “Original (installed configuration)”.
2. Add a key of the type String Value, name it connectioncontext and give it the value of 1
3. Restart your AOS
If you have multiple AOS-instances you need to repeat the above for each AOS server.
Now we can use this statement to get a list of active queries:
SELECT cast(context_info AS VARCHAR(128)) AS [Connection info] , * FROM sys.dm_exec_sessions WHERE program_name LIKE '%Dynamics%' AND host_name LIKE '<AOSNameMask>'
If your AOS servers are named MyAOS01, MyAOS02, MyAOS03 and so forth put in MyAOS% as the <AOSNameMask>.
Now, the result is in the first column a variety of information including the AX user id and the AX session id. This can be matched directly to the online users overview within AX.
You can go the other way around by adding this
AND context_info like ' <AXUserId>%'
where <AXUserId> is the relevant id of the user in AX. Notice the initial blank in the range value.