Wednesday, July 01, 2009

Ecological font

For those who wants to help saving the Earth, http://www.ecofont.eu

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.

Monday, September 22, 2008

Windows Authentication with Firefox

With Firefox, follow the steps below to enable Windows authentication for your servers.

1. Open Firefox 2.x or 3.x

2. Navigate to the url "about:config"

3. Locate the following preference names and set their value with the list of servers separated with comma.

  • network.automatic-ntlm-auth.trusted-uris
  • network.negotiate-auth.delegation-uris
  • network.negotiate-auth.trusted-uris

Your value should look something like this: localhost,myserverA,myserverB

Tuesday, September 02, 2008

Google's browser...

Google had just made the first BETA version of his (open-source) browser available.

First impression is good! The browser starts really fast with a simple UI as Google knows hwo to make them.

Browsing is also fast, using the same rendering engine as Safari (i.e WebKit)

Oops, I also forgot to give its name: Google Chrome

Read the comics explaining the history of the browser,
Download and install it,
And finally check that your web sites render properly with Safari and Chrome ;-) 

Wednesday, August 13, 2008

Tips for MyGeneration

I am a big fan of code generation based on templates. It gives all the flexibility you are expecting when coding by hand, but still

  • Increase your productivity
  • Decrease maintenance efforts
  • Code consistency across your project(s)
  • etc...

I have been using MyGeneration for a while now and I recently found a good post from Michael Freidgeim summarizing most of the good links you need if you use it.

Tuesday, May 27, 2008

Replacing the configuration in Web Deployment Projects

I am using Microsoft Web Deployment Projects in order to deploy automatically my nightly build on the development and test servers.

It worked great but I struggled quite some time trying to replace the configuration section.

Well, it was as stupid as that you cannot replace the whole system.serviceModel because it's not a configuration section, but is a configuration section group...and guess what?

WDP can only replace configuration sections and not configuration section groups.

What you can do though is replacing a section within the section group.

Within system.serviceModel, you can replace the client configuration section for instance using the replacement string "system.serviceModel/client=system.serviceModel.client.dev.config;"

Monday, May 26, 2008

SQL Code Prettifier from Simple-Talk

Use the Simple-Talk Prettifer to format your code (SQL, C#, VB and Python)http://extras.sqlservercentral.com/prettifier/prettifier.aspx in your web pages.

Update (23-March-10): I have been recently using http://www.manoli.net/csharpformat/, which does a better job and allow xml formatting.

Wednesday, May 14, 2008

Calling a WCF Service

Based on WCF best practices, calling a WCF service should not be wrapped in a using statement as exceptions can be raised (http://msdn2.microsoft.com/en-us/library/aa355056.aspx). Below is a code snippet highlighting the best practice:

ServiceClient client = new ServiceClient();

try
{
client.MyOperation
();
client.Close
();
}
catch (CommunicationException e
)
{
//Handle exception if necessary
client.Abort
();
}
catch (TimeoutException e
)
{
//Handle exception if necessary
client.Abort
();
}
catch (Exception e
)
{
//Handle exception if necessary
client.Abort
();
throw
;
}

However the code to write to do so is quite painful, hence I have written a VS code snippet (wcfproxycall.snippet) to minimize the pain.

To install the code snippet, simply copy the attached snippet to "My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets"

When you need to call a proxy, type wcfproxycall in your code and hit the Tab key to expand the code snippet.

  • Fill the highlighted fields
  • Use the tab key to navigate to the next field
  • Hit Enter to complete when all fields are filled

Thursday, April 17, 2008

Grant permissions to all stored procedures in a database

SQL Server 2005 improves on the current situation by making the EXECUTE permission grantable at the database scope.

What it means is that we can issue a statement like the example below and this will GRANT execute permissions on ALL existing stored procedures and scalar functions AND all subsequently created ones.

GRANT EXECUTE TO [myUser] AS [dbo]

If you only make use of stored procedures to access your database and have not implemented a complex security model, this is probably the easiest and cleanest way to manage access rights.

If users' Windows accounts are used to connect to the database, you will prefer creating a role like db_storedprocedures_executor and assigning it the EXECUTE permission. Then it is very much like the existing fixed database roles such as db_datareader.