Of Code and Me

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

DTC Error with NServiceBus and Linq To Sql August 31, 2010

Filed under: Error,Linq to Sql,NServiceBus — Rupert Bates @ 8:08 pm

I spent most of the morning debugging the following error which I got when using Linq To Sql with NServiceBus:


The transaction has already been implicitly or explicitly committed or aborted

This occurred whenever I tried to do any data access from within a service running in the NServiceBus generic host, and confused the hell out of me because I knew the same code was working fine outside of the service.

In the end I eventually tracked it down to an error with the Distributed Transaction Coordinator service which NServiceBus uses to handle transactions. By using the DTCPing tool I was able to see that while my workstation could connect to the database server the server could not then connect back to my machine.

A bit more digging revealed that this was because the DNS entry for my computer’s host name was incorrect (I sometimes have to change it to access certain sets of servers and the DNS evidently can’t keep up).  Apparently this error or one very like it can also be caused by incorrect firewall settings.

As a temporary workaround I got it working by putting the correct IP in an entry in the server’s hosts file; since this is not a situation that will happen in a production environment I’m not that concerned. I believe another solution would be to run my service AsA_Client in NServiceBus and handle the transactions myself; I will probably end up doing this as it gives me a bit more control over how the transactions are implemented.

Loving NServiceBus though…

Advertisements
 

Compile Aspx pages at compile time using the AspNetCompiler build task August 18, 2010

Filed under: Asp.Net,Web — Rupert Bates @ 1:20 pm

By default Asp.Net web applications don’t compile aspx files (only the code behind). This means that you can have errors in them which don’t appear until you actually hit the page.

To change this so that your aspx files get compiled along with all the rest of your code do the following:

  • Unload your web app (right click on the project and select ‘Unload Project’)
  • Open the csproj file in a text editor (right click on the project and select ‘Edit myProjectName.csproj’)
  • At the bottom of the file find the comment which says ‘To modify your build process…’ and insert the following after that comment:

<Target Name="AfterBuild">
<AspNetCompiler  VirtualPath="temp"  PhysicalPath="$(ProjectDir)" />
 </Target>

 

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"