Wednesday, November 4, 2009

Demote 2003 Domain Controller: NETLOGON Timeout

As you may know, I occasionally copy information here which I feel needs better exposure on the web. This is just such a post.

I recently tried to demote a server 2003 domain controller (using dcpromo), and hit the following error message:

The operation failed because:

Failed to configure the service NETLOGON as requested

"The wait operation timed out"
This is a particularly useless message because the actual problem has nothing to do with netlogon.

I corrected this problem by modifying the TCP/IP settings to point DNS at the remaining domain controller (e.g. remove or any other IP which points to the machine being demoted).

Tuesday, September 29, 2009

Running IE6 in Windows 7 with Virtual PC

With the advent of Windows 7 and improved application virtualization, legacy browser testing has been greatly simplified.

Thanks to the XP Mode vmc that Microsoft provides here, it is quite easy to setup an instance of IE6 to run almost seamlessly alongside your native Windows 7 apps.

After installing Windows Virtual PC and the XP Mode vhd, perform the following steps:
  1. In Windows Explorer, navigate to "c:\documents and settings\all users\start menu".
  2. Right-click and select New -> Shortcut.
  3. Type in or whatever you would like your home page to be.
  4. Give the shortcut a name (I called mine "IE6").
  5. Finish the wizard, log off, and close the virtual PC.
  6. In your Windows 7 start menu you will now find a folder at All Programs -> Windows Virtual PC -> Windows XP Mode Applications which contains the shortcut you just created. Click this shortcut and TADA! IE6 runs in a window of it's own.
One limitation of this approach is that you can only have one instance of any XP Mode application running at one time. You may be able to open multiple IE6 instances by creating more than one shortcut in the xp start menu, but I didn't try it.

Sunday, August 30, 2009

No DVD Sound in Windows 7

I installed Windows 7 on an older (4 years) laptop this past weekend and encountered a rather irksome problem that has a very simple fix.

  • Audio works fine, until you stick in a DVD and try to play it with WMP12: no sound.
  • WMP12 playing mp3's is fine, but stick in a DVD: no sound.
  • Load a DVD ISO on a virtual drive and try to play: no sound.
Because of some trouble I had with the Realtek drivers for windows 7, and the Sony DVD drive, I was not certain at this point where precisely the problem lay. Searching a bit for Realtek, DVD and Sony's DW-D56A didn't turn anything up, so I started looking more broadly.

Turns out a post on AVForums by Damernath pointed out a very simple solution that worked like a charm. I repeat below for your benefit:
  1. Go to: Control Panel -> Sound
  2. On the "Playback" tab select "Speakers" and click "Properties"
  3. On the "Advanced" tab uncheck "Allow applications to take exclusive control of this device"
That's it. Restart WMP and watch your DVD glory.

Thursday, August 6, 2009

MS Deploy RC1 Install ... Odd!

In upgrading from MS Deploy Beta1 to RC1, I found an undocumented oddity which could stump you for who knows how long.

If you install the RC without first uninstalling the beta, the Web Deployment Agent Service refuses to start. From the command line, "net start msdepsvc" returns

The service did not report an error

And no error is logged in the Event Log either.

The fix? Simple, just go into Programs and Features, select the Web Deployment Tool Release Candidate 1 and choose "Repair".

All fixed.

Thursday, June 18, 2009

Clearing Sql 2008 Management Studio Saved Passwords

In Management Studio 2005, the saved connections, usernames, and passwords could be cleared out by deleting the mru.dat file. However, in SSMS 2008 there is no equivalent data file. A similar effect can be achieved by deleting the SqlStudio.bin file. This will affect other settings, but for now it's the best solution.

In Vista, this file is located at:
C:\Users\{username}\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin
And for XP:
C:\Documents and Settings\{username}\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\SqlStudio.bin
Aaron Bertrand has blogged a bit more about this here.

Thursday, May 7, 2009

Server 2008 Loopback Adapter Forwarding

I don't know why this information is so hard to find, but I'm copying it here to hopefully help a few more people find it.


In server 2008, loopback adapters are slightly different than in earlier windows operating systems. In order to forward traffic coming from your physical connection through the ips associated with the loopback you have to enable forwarding on your default connection.
netsh interface ipv4 set interface "local area connection" forwarding=enabled

Thursday, January 8, 2009

NHibernate: What the heck is "clazz_"?

Being a reticent fellow, it isn't often that I blog twice in as many days, but I ran into an issue with NHibernate joined-subclasses and ISQLQuery twice in two different instances in the past two days.

After searching around a good deal for any information I could find about adding entities to SQL queries in NHibernate, I finally found something that pointed me in the right direction, and I thought I'd give it a post to hopefully assist any other unfortunate Hibernate users out there who may encounter this problem.

The Error

You can reproduce this error by creating a class inheritance like:
<class name="BaseEntity" table="BaseEntity">

  <joined-subclass name="FirstChildEntity" table="FirstChildeEntity">

  <joined-subclass name="SecondChildEntity" table="SecondChildeEntity">
Now when you run a SQL query like so:
select * 
  BaseEntity be
  left join FirstBaseEntity fbe on be.Id = fbe.EntityId
  left join SecondBaseEntity sbe on be.Id = sbe.EntityId
We get the following error message.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: clazz_

Stack Trace:
[IndexOutOfRangeException: clazz_]
  System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) +2307341
  System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) +258
  NHibernate.Driver.NHybridDataReader.GetOrdinal(String name) +33
  NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name) +133
  NHibernate.Type.NullableType.NullSafeGet(IDataReader rs, String name, ISessionImplementor session, Object owner) +13
  NHibernate.Loader.Loader.GetInstanceClass(IDataReader rs, Int32 i, ILoadable persister, Object id, ISessionImplementor session) +215
  NHibernate.Loader.Loader.InstanceNotYetLoaded(IDataReader dr, Int32 i, ILoadable persister, EntityKey key, LockMode lockMode, EntityKey optionalObjectKey, Object optionalObject, IList hydratedObjects, ISessionImplementor session) +78
  NHibernate.Loader.Loader.GetRow(IDataReader rs, ILoadable[] persisters, EntityKey[] keys, Object optionalObject, EntityKey optionalObjectKey, LockMode[] lockModes, IList hydratedObjects, ISessionImplementor session) +636
  NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies) +285
  NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +756   NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +105
  NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +236

The Research

The error message is not very helpful.  All we can really tell from the stack trace is that it's trying to do a field name lookup, but what field is "clazz_"?

If you are like me, you immediately pull open Google and run a search for anything about Nhibernate/Hibernate, clazz_, and createsqlquery.  One of the few useful results is this anotated source code on FishEye, from which we can see that Hibernate uses the "clazz_" string as a column discriminator.  Great!  But for what purpose?

Examining the code a little further, and reading the comments, we can discover that "clazz_" is a column added to the generated sql to differentiate between polymorphic classes, i.e. subclasses.  This is and old version, but it seems we're on the right trail.

A quick search on the forums (which, for some reason, aren't indexed by Google) reveals some 8-10 threads concerning this very issue.  Sadly, it's not the good folks on the Hibernate project who are the most helpful in this case.  Thanks, however, to a fellow by the name of credmond, we can glean a little more info about this "clazz_" column.

To get any further, we're going to have to get our hands dirty.  Let's run a standard HQL query and see what kind of SQL it generates.
Session.CreateQuery("from BaseEntity").List();
The resulting SQL string looks something like this (with most of the fields removed for space):
  entity0_.Id as Id27_, 
  [base entity fields],
  [first child entity fields],
  [second child entity fields],
    when entity0_1_.EntityId is not null then 1 
    when entity0_2_.EntityId is not null then 2 
    when entity0_.Id is not null then 0 
  end as clazz_ 
  BaseEntity entity0_ 
  left outer join FirstChildEntity entity0_1_ on entity0_.Id=entity0_1_.EntityId 
  left outer join SecondChildEntity entity0_2_ on entity0_.Id=entity0_2_.EntityId
We can see here the case statement credmond spoke of.  My first question is: what happens if we change the order of the joined-subclasses in the mapping file?  The resultant SQL looks much the same, except for one important aspect: the aliases in the from clause are reversed!
  BaseEntity entity0_ 
  left outer join SecondChildEntity entity0_1_ on entity0_.Id=entity0_1_.EntityId
  left outer join FirstChildEntity entity0_2_ on entity0_.Id=entity0_2_.EntityId
So it appears that the number associated with each subclass is dependent upon the order of the subclasses in the mapping file.  Thus we find our (ugly) workaround.

The Workaround

We can get our code working (albeit, not very pretty) by adding the "clazz_" discriminator column manually to our SQL:
select *,
    when fbe.EntityId is not null then 1 
    when sbe.EntityId is not null then 2 
    else 0 
  end as clazz_
  BaseEntity be
  left join FirstBaseEntity fbe on be.Id = fbe.EntityId
  left join SecondBaseEntity sbe on be.Id = sbe.EntityId
To make sure this doesn't break down the road, a comment should be added to the mapping file to convey the importance of maintaining the order of the joined-subclass descriptions.

While I don't like this solution, it's the simplest one I've found until the Hibernate team fixes what I consider to be a bug in their implementation of joined-subclasses.

Wednesday, January 7, 2009

HTTP Error 500.19: "This configuration section cannot be used at this path."

Occasionally, when setting up a new Vista box with IIS 7 and ASP.NET, I'll encounter this error for one application or another.

Simply Googling the generic header "500.19 Internal Server Error" turns up too much unrelated information.  You have to look a little further down and see the little message about:
"This configuration section cannot be used at this path.  This happens when the section is locked at a parent level.


Once you've noticed this key piece of information, the steps to fixing it are simple and few:

  1. Examine the source to figure out which section has an override lock on it.  In my case, this was
  2. Locate your applicationHost.config file.  This is generally located at %SystemRoot%/system32/inetserv/config/applicationHost.config.
  3. Within applicationHost.config, find the override section from step 1 and change it's overrideModeDefault to "Allow".


If your application is in a directory beneath another IIS application, debugging this error can become a little more tricky since there are multiple places the section could have been locked.  You should still begin by checking the applicationHost.config as the most likely place, but failing there, look through any other web.configs above your application.