How to fix SQL Server orphaned users

When you restore a database, often the UserSID is different between the database and the server users, so you end up with Orphaned Users.

To resolve this run the following when connected to the restored database.

EXEC sp_change_users_login Report

That will return a list of all orphaned users in the selected database.

If you already have a login id and password for this user, fix the orphaned user by:

EXEC sp_change_users_login Auto_Fix, user

If you want to create a new login id and password for this user, fix it by :

EXEC sp_change_users_login Auto_Fix, user, login, password

Apache far future expires

With web page designs becoming richer with additional css, javascript and other media it is important to minimise the number of requests a browser has to make to download a web page.  By using Expires headers you can stop the unnecessary HTTP requests on all subseqent pages using the same css/javascript and media.

An additional benefit of using expires headers is they reduce the number of requests, allowing web pages to load quicker and use less bandwidth.  This can have additional benefits if your visitors have limited bandwidth (for example accessing the site via a mobile)

For Apache the quickest way is to add the following to your .htaccess file.

<FilesMatch "\.(gif|png|jpg|css|js|swf|flv|ogg)$">
ExpiresActive On
ExpiresDefault "access plus 4 weeks"
FileETag none
</FilesMatch>

This will send an expires header allowing the file to not be requested for 4 weeks for all files having the extensions .gif, .png, .jpg, .css, .js, .swf, .flv and .ogg.

For the above to work you need to ensure that the Apache mod_expires is enabled. In debian/Ubuntu this can easily be done by running

a2enmod expires

Issues

  • Any files with caching headers need to have a versioned filename, otherwise the changed files will not be downloaded when they are updated until the expires date has passed

Yahoo Developer Network has a discussion of adding an Expires header