Resolution
The user running the application needs to have the following permissions and group membership set:
- The user is a server farm administrator.
- The user has Read and Write permissions on the content database.
- The user is a site collection administrator.
- The user has permissions to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.