How to migrate multiple sites from IIS 6 to IIS 7

This is a quick guide on how to migrate all sites from IIS 6 to IIS 7. You can probably use the same commands to move sites from one IIS 7 to another.

Everything will be migrated, including application pools, virtual directories, SSL certficiates etc.

1. Download and install Web Deployment Tool on both source and destination servers: http://www.iis.net/download/webdeploy Continue reading

How to add new column to a MSSQL table between two existing columns

It’s possible but not as easy as ALTER TABLE [table] ADD COLUMN [column] [type] AFTER [anothercolumn]; like supported in MySql.

We need to drop all contraints, create a temporary table with the new structure, copy all data to the temporary table, drop the old table and rename the temporary table.

Below is a script that adds the column newcolumn between place and name in a table named mytable.

ALTER TABLE [mytable] DROP CONSTRAINT [PK_mytable]
ALTER TABLE [mytable] DROP CONSTRAINT [DF_mytable_place]
ALTER TABLE [mytable] DROP CONSTRAINT [DF_mytable_name]
 
CREATE TABLE tmp_mytable (
	[item_id] [int] IDENTITY(1,1) NOT NULL,
	[place] [int] NOT NULL,
	[newcolumn] [nvarchar](255) NOT NULL,
	[name] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_mytable] PRIMARY KEY CLUSTERED 
(
	[item_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
 
ALTER TABLE [tmp_mytable] ADD  CONSTRAINT [DF_mytable_place]  DEFAULT ((1)) FOR [place]
ALTER TABLE [tmp_mytable] ADD  CONSTRAINT [DF_mytable_name]  DEFAULT ('') FOR [name]
ALTER TABLE [tmp_mytable] ADD  CONSTRAINT [DF_mytable_newcolumn]  DEFAULT ('newvalue') FOR [newcolumn]
 
SET IDENTITY_INSERT dbo.tmp_mytable ON
IF EXISTS(SELECT * FROM [mytable])
	 EXEC('INSERT INTO [tmp_mytable] (item_id, place, name)
		SELECT item_id, place, name FROM [mytable] WITH (HOLDLOCK TABLOCKX)')
SET IDENTITY_INSERT dbo.tmp_mytable OFF
 
DROP TABLE mytable;
EXECUTE sp_rename N'tmp_mytable', N'mytable', 'OBJECT';

If you don’t care about the placement you can add a column to the end of the table using this command:

ALTER TABLE mytable ADD newcolumn [nvarchar](255) NOT NULL CONSTRAINT DF_mytable_newcolumn DEFAULT 'newvalue'

How to easily migrate mailboxes from Exchange server 2003 to 2010

I have been trying to figure out a way to move a few mailboxes from Exchange server 2003 to 2010. There is no trust relation between the two servers and they are on different networks so the included Move Request feature does work. I only seem to be able to find very complicated and time consuming ways of doing that mainly targeted for Exchange servers with hundreds or thousands of mailboxes or involving expensive migration tools. Continue reading

How to test disk performance in Linux

A lot of performance issues can be caused by poor disk performance. Here’s how to test the read and write performance on a Linux system using dd.

1. Write a file 2x the size of the RAM to make sure we get the real write rate. In this example the RAM of the server is 1 GB so I’m writing a 2 GB file (8KB * 250000 = 2GB). You can adjust the number of blocks to make it suitable for the amount of RAM in your system .

time sh -c "dd if=/dev/zero of=ddfile bs=8k count=250000 && sync"

2. Write a new file equal to the amount of RAM in the system to flush out the data cached with last action (8KB * 125000 = 1GB).

dd if=/dev/zero of=ddfile2 bs=8K count=125000

3. Test the read speed

time dd if=ddfile of=/dev/null bs=8k

Case insensitive functions not working properly with special international characters

I was creating a PHP-level search function using stripos to check if the search query was found in a string. Everything was working perfectly except special characters were still case sensitive.

Turns out the problem is that the default locale was set to one not supporting those characters. To fix it, change the default locale to a better match or set the locale manually using the setlocale function:

setlocale(LC_ALL, 'is_IS');

Generating self-signed certificate

1. Download and install Windows SDK

2. Open command prompt as Administrator and cd to this directory: C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin

2. Create a root certificate

makecert -pe -n "CN=Test Root Authority" -ss my -sr LocalMachine -a sha1 -sky signature -r "c:\Test Root Authority.cer"

3. Create the new certificate and sign it with the newly generated self-signed root certificate

makecert -pe -n "CN=yourdomain.com" -ss my -sr LocalMachine -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -in "Test Root Authority" -is my -ir LocalMachine -sp "Microsoft RSA Schannel Cryptographic Provider" -sy 12 c:\yourdomain.cer