Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Run NServiceBus generic host as 32bit process on 64bit machine September 7, 2010

Filed under: Error,NServiceBus,Systems Administration — Rupert Bates @ 3:37 pm

I recently encountered the following error when deploying a service in the NServiceBus generic host (NServiceBus.Host.exe) on a 64bit machine,


System.InvalidOperationException: The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine.

It turns out that this is actually a symptom of a problem which can show itself in a number of ways and is caused by running a service which depends on a 32bit dll (in this case the Microsoft Jet drivers) on a 64bit system in the generic host.

To fix it you can create a version of the generic host which is configured to run as 32bit as follows:

Run a visual studio command prompt and cd to the directory where NServiceBus.Host.exe is.  You will also need the NServiceBus.snk file from the NServiceBus download in the same directory so that you can resign the assembly after configuring it

At the command prompt type:

corflags /32BIT+ /Force NServiceBus.Host.exe

sn -R NserviceBus.Host.exe NServiceBus.snk

You can now deploy this version of the host onto your 64bit server and services which use it will run in 32bit mode

 

Change the Home Directory of an IIS 6 website using Powershell 2 and WMI August 3, 2010

Filed under: Powershell,Systems Administration,Web,Windows — Rupert Bates @ 4:13 pm

This function will set the home directory of an IIS 6 website using Powershell 2 (it will not work with v1).

You need to pass it the site description (from the Web Site tab in IIS), the new path and the server your website is running on (this can be a machine name or an IP address).

You wouldn’t believe how long it took me to get this working.


Function SetHomeDirectory($SiteDescription, $NewPath, $serverName)
{
 $query = "ServerComment = '" + $SiteDescription + "'"
 $webserver = Get-WMIObject -class IIsWebServerSetting -namespace "root\microsoftiisv2" -Filter $query -computer $serverName -authentication 6
 $nameQuery = "Name = '" + $webserver.Name + "/root'"
 $webdir = Get-WMIObject -class IIsWebVirtualDirSetting -namespace "root\microsoftiisv2" -Filter $nameQuery -computer $serverName -authentication 6
 $webdir.Path = $NewPath
 Set-WmiInstance -InputObject $webdir
}
SetHomeDirectory "mysite.co.uk" "d:\websites\mysite" "myServer"
 

Update environment variables in Powershell May 20, 2010

Filed under: Powershell,Systems Administration — Rupert Bates @ 9:27 am

To update an environment variable in Powershell in a way that lasts beyond the current session you can use the SetEnvironmentVariable method:

[Environment]::SetEnvironmentVariable(“theVariableToSet”, “theNewValue, “User”)

The final parameter determines the scope of the variable and can be one of Process, User or Machine.

So to add to your path you can use the following:

$path = [environment]::GetEnvironmentVariable(“path”,”User”) + “C:\Program Files\Git\bin;”
[Environment]::SetEnvironmentVariable(“path”, $path, “User”)

 

Setup Apache on Ubuntu April 8, 2010

Filed under: Linux,Systems Administration,Web — Rupert Bates @ 4:21 pm

Go to System -> Administration -> Synaptic Package Manager

Find the apache2 package (using the quick search is the easiest way), click ‘Mark for installation’ and then click the ‘Apply’ button

When the install is completed check that:

  1. the Apache program files are in /etc/apache2/
  2. there is an index.html file in /var/www/ (this is the root of the default vhost)
  3. apache2 is running, the command: ps -A | grep apache2 should return at least 1 result
  4. browsing to http://localhost/index.html serves that file successfully (I needed to restart it after the install before I could browse to localhost)

To start, stop and restart Apache :
/etc/init.d/apache2 start
/etc/init.d/apache2 s
/etc/init.d/apache2 restart

 

Find the level of index fragmentation in a Sql Server database December 4, 2009

Filed under: Sql Server,Systems Administration — Rupert Bates @ 11:48 am

This will return the level of fragmentation for every index in the current database:

SELECT b.NAME, [a].*
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL,
     NULL, NULL, NULL) AS a
     JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id
WHERE [a].index_id <> 0
ORDER BY avg_fragmentation_in_percent desc
 

Connect to IIS 6 over WMI with WMI CIM studio September 10, 2009

Filed under: Systems Administration — Rupert Bates @ 4:08 pm

Connect to:

\\[ServerName]\root\MicrosoftIISv2

In the connection dialog:

If you are logged in as a user who has admin rights on the server then check ‘Login as current user’, otherwise uncheck it and enter the credentials of a user who does.

Click ‘Options>>’ button:

Set Impersonation level to ‘Impersonate’

Set Authentication level to ‘Packet Privacy’

Check ‘Enable all privileges’

Click ‘OK’ and hey presto!