Impersonation - MarkMpn/Sql4Cds GitHub Wiki

All queries run with the security permissions of the logged in user. However, if the user has impersonation permissions, it's possible to run a query as another user. This is currently only available in the XrmToolBox version of the tool, not the SSMS plugin.

Using the user interface

The status bar at the bottom of the SQL 4 CDS window shows the current user name and a drop down arrow. Click this to open the impersonation menu. Select "Impersonate" to find and select a user to impersonate, then click OK. Open the menu again and click Revert to switch back to the original user.

While you are impersonating another user, that user's name will be shown in the status bar in place of your own, and a warning triangle will be shown next to it.

Using SQL

Use the EXECUTE AS command to select a user to impersonate, and REVERT to switch back to the original user.

With the EXECUTE AS command you can specify either a login or a user to impersonate. SQL 4 CDS uses these to find the user to impersonate as follows:

EXECUTE AS LOGIN

EXECUTE AS LOGIN = '[email protected]'

This finds the user with the requested domainname attribute.

EXECUTE AS USER

EXECUTE AS USER = 'A382DE2C-3377-49DE-9724-54C017B39806'

This finds the user with the requested systemuserid attribute.