Minimum database permissions for using SqlDependency with SQL Server 2005

If you wonder what minimum permissions you need to use SqlDependency with SQL Server 2005 then look no further. This code project article definitely works and is the most complete one I've found. Note that setting minimum database permissions for notification isn't exactly the easiest task on the planet. Actually through experimenting I've managed to create a service_queue in sys.objects that I couldn't remove without restoring the database entirely (luckily I am using RedGate's SQL Backup 5 for backing up my databases - it makes the backup and restore process so easy, not to mention the encryption and compression capabilities).

Anyway, after restoring the database to the initial non-notification enabled point (clean state), I managed to apply proper minimum permissions following the mentioned article.

Righthand has joined LLBLGenPro partners

I am proud to announce that today, after years of experience with LLBLGenPro development, I've become an official LLBLGenPro partner.


As such I am offering consultancy and development with LLBLGenPro, the #1 ORM product for .net. Do you want to speed up your database application development, reduce the number of errors in code, develop a database independent application and, most importantly, reduce the development costs? I firmly believe that LLBLGenPro is an excellent product that addresses all of these challenges.

If you are interested, contact me through contact form or through e-mail or any other way...

Visual Studio 2008 SP1 most peculiar installation known issue

I was reading VS2008 SP1 known issues file and this issue struck me:

2.1.4 Visual Studio 2008 SP1 installation fails when the Windows Vista sidebar is enabled.
Visual Studio 2008 SP1 installation fails when the Windows Vista sidebar is on.

To resolve this issue:

1. Right-click the Sidebar icon in the notification area, at the far right of the taskbar.
2. Click "Exit".

How can Vista sidebar interfere with VS2008 SP1 installation? This has to be the most peculiar installation issue I have seen in a while. Well, it didn't complain when I installed the SP1.

Go figure.

Creating wrappers for sealed and other types for mocking

Did you ever wanted to mock a sealed class or non-virtual methods? Unless you are using TypeMock you are in for some coding as there is no easy way to mock them just like that (I am fiddling with MOQ but AFAIK no mock framework is capable of mocking sealed classes with exception of TypeMock). The general pattern I see is to create a wrapper class that implements an interface (you have to create that interface, too, most of the times). Let's see an example with a class Tubo:

public class Tubo { public void SomeMethod() { } public int SomeProperty { get { return 1; } }

To be able to mock this class you have to create ITubo interface and a TuboWrapper class like this:

public interface ITubo { void SomeMethod(); int SomeProperty { get; } } public class TuboWrapper: ITubo { private Tubo tubo = new Tubo(); public void SomeMethod() { tubo.SomeMethod(); } public int SomeProperty { get { return tubo.SomeProperty; } } }

It sounds like highly boring and time consuming exercise, doesn't it. Specially if you have to wrap a class rich with methods and properties. One could argue that you should think before creating non-mockable types. True, but one can't help when dealing with non-user types (i.e. .net framework types).

One solution would be to go duck typing as Phil Haack explains. There is also a library that enabled such typing. However, there are two arguments against duck typing:

  • slight performance hit
  • you still have to code the interface

So, it goes half way to solve the problem.

That's why I've created a CodeSmith template that generates both wrapper and interface for you out of a type in an assembly. Note that this is a very raw version that would work with types located in System and System.Core assemblies (and perhaps others that are linked to the template) as I really don't have too much time right now. I might enhance it in the future.

Here is a sample configuration for creating ReaderWriterLockSlim wrapper:

<?xml version="1.0"?> <codeSmith xmlns=""> <propertySets> <propertySet output="WrapperGenerator.cs" template="..\CodeSmith Templates\WrapperGenerator.cst"> <property name="Postfix">Wrapper</property> <property name="InternalQualifier">private</property> <property name="IgnoreObjectMethodsAndProperties">True</property> <property name="Types"> <stringList> <string>System.Threading.ReaderWriterLockSlim</string> </stringList> </property> <property name="Namespace">Namespace.Wrappers</property> </propertySet> </propertySets> </codeSmith>

and here is autogenerated code:

namespace Namespace.Wrappers { using System; #region ReaderWriterLockSlim wrapper public interface IReaderWriterLockSlim { #region Properties bool IsReadLockHeld { get; } bool IsUpgradeableReadLockHeld { get; } bool IsWriteLockHeld { get; } System.Threading.LockRecursionPolicy RecursionPolicy { get; } int CurrentReadCount { get; } int RecursiveReadCount { get; } int RecursiveUpgradeCount { get; } int RecursiveWriteCount { get; } int WaitingReadCount { get; } int WaitingUpgradeCount { get; } int WaitingWriteCount { get; } #endregion #region Methods void EnterReadLock (); bool TryEnterReadLock (TimeSpan timeout); bool TryEnterReadLock (int millisecondsTimeout); void EnterWriteLock (); bool TryEnterWriteLock (TimeSpan timeout); bool TryEnterWriteLock (int millisecondsTimeout); void EnterUpgradeableReadLock (); bool TryEnterUpgradeableReadLock (TimeSpan timeout); bool TryEnterUpgradeableReadLock (int millisecondsTimeout); void ExitReadLock (); void ExitWriteLock (); void ExitUpgradeableReadLock (); void Dispose (); #endregion } public partial class ReaderWriterLockSlimWrapper: IReaderWriterLockSlim { private System.Threading.ReaderWriterLockSlim core; public ReaderWriterLockSlimWrapper() { this.core = new System.Threading.ReaderWriterLockSlim(); } public ReaderWriterLockSlimWrapper(System.Threading.ReaderWriterLockSlim core) { this.core = core; } #region Properties public bool IsReadLockHeld { get { return core.IsReadLockHeld; } } public bool IsUpgradeableReadLockHeld { get { return core.IsUpgradeableReadLockHeld; } } public bool IsWriteLockHeld { get { return core.IsWriteLockHeld; } } public System.Threading.LockRecursionPolicy RecursionPolicy { get { return core.RecursionPolicy; } } public int CurrentReadCount { get { return core.CurrentReadCount; } } public int RecursiveReadCount { get { return core.RecursiveReadCount; } } public int RecursiveUpgradeCount { get { return core.RecursiveUpgradeCount; } } public int RecursiveWriteCount { get { return core.RecursiveWriteCount; } } public int WaitingReadCount { get { return core.WaitingReadCount; } } public int WaitingUpgradeCount { get { return core.WaitingUpgradeCount; } } public int WaitingWriteCount { get { return core.WaitingWriteCount; } } #endregion #region Methods public void EnterReadLock() { core.EnterReadLock(); } public bool TryEnterReadLock(TimeSpan timeout) { return core.TryEnterReadLock(timeout); } public bool TryEnterReadLock(int millisecondsTimeout) { return core.TryEnterReadLock(millisecondsTimeout); } public void EnterWriteLock() { core.EnterWriteLock(); } public bool TryEnterWriteLock(TimeSpan timeout) { return core.TryEnterWriteLock(timeout); } public bool TryEnterWriteLock(int millisecondsTimeout) { return core.TryEnterWriteLock(millisecondsTimeout); } public void EnterUpgradeableReadLock() { core.EnterUpgradeableReadLock(); } public bool TryEnterUpgradeableReadLock(TimeSpan timeout) { return core.TryEnterUpgradeableReadLock(timeout); } public bool TryEnterUpgradeableReadLock(int millisecondsTimeout) { return core.TryEnterUpgradeableReadLock(millisecondsTimeout); } public void ExitReadLock() { core.ExitReadLock(); } public void ExitWriteLock() { core.ExitWriteLock(); } public void ExitUpgradeableReadLock() { core.ExitUpgradeableReadLock(); } public void Dispose() { core.Dispose(); } #endregion } #endregion }

Do you still want to code them by hand? Or do you want to use this template? Rhetoric question? What do you think?

Anyway, go get the template here.

Can't start World Wide Web Publishing Service because of Windows Process Activation Service

Recently I had to check out an application on my workstation and found out that the "Default Web Site" is stopped for some reason. After trying to start it I've got this message:


So I've tried to start the mentioned services only to get a new error message (WWW PS):


The mentioned dependency is the other stopped service: WAS or better Windows Process Activation Service (the original message has left out the Process word). After trying to start WAS I've got another error message:



And here the error path comes to an end. Which file? I could have used Sysinternals' FileMonitor to find out what file the service is looking for. Rather I've decided to Google first as it is faster. After experimenting with search string a bit I've found this blog entry which points to this solution. After creating the mentioned folder and applying proper security settings IIS started to work once again.