Tuesday, December 16, 2008

Impersonate a user in SQL2005

It's often useful to run a stored procedure or any script with the permissions of another user (i.e. impersonate a different user than the current one).

It is possible to do so since SQL 2005 is out there, and is as simple as shown below:

EXECUTE AS USER = 'anotheruser'
GO

--Your SQL Statement

REVERT
GO


Note the REVERT command to restore the original user.

In order to impersonate a user, you will grant the IMPERSONATE rights on the user you want to impersonate to the user who will be impersonated it.

GRANT IMPERSONATE ON USER:: [AnotherUser] TO [MyCurrentUser];

Users with sysadmin role can impersonate any user, without being granted the IMPERSONATE right.

For all details, check the online reference @ http://msdn.microsoft.com/en-us/library/ms181362.aspx

Running multiple instances of Firefox

It is always useful to have several browser instances when developing and testing so that you can "impersonate" several different users at the same time.

IE does it for each different window; Firefox always shares the same instance even for different windows.

As per the title of this entry, you already know that Firefox allows you to do it but the "feature" is simply not available as a simple check box.

1. Start Firefox with the Profile Manager
If you installed Firefox in the default installation location, open a command prompt and run "C:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -ProfileManager
2. Create a new profile
You can choose any name but I used "testprofile"
3. You are ready now to run a second instance of Firefox with the testprofile
Again, if you installed Firefox in the default installation location, open a prompt and run "C:\Program Files\Mozilla Firefox\firefox.exe" -no-remote -P testprofile
If you need to run the other instance on a regular basis, you will simply create a shortcut with the command line above.

Need to run more than 2 instances at a time? You will need to repeat the process above and create more test profiles.

For more command line arguments, check the Firefox KB.