Monday, February 15, 2016

Reporting services ‘nullreferenceexception’

I spent most of Valentines day this year trying to fix SharePoint 2010 and Reporting services.

I’ve decided to blog about the experience because it was so frustrating and the solution was not what I would have expected.

The sequence of events was’;

  • We removed the ‘ReportCentre’ content database from the SharePoint 2010 farm
  • Moved the data file to another drive in SQL
  • Added the content database back to the farm

The outcome of that was that the SharePoint site collection was online and browseable but none of the SQL Reporting Services Reports would render.

When we looked in the SSRS log files, this is all we got:

webserver!ReportServer_0-1!1e78!02/14/2016-16:21:26:: e ERROR: Reporting Services error Microsoft.ReportingServices.Diagnostics.Utilities.SharePointException: Report Server has encountered a SharePoint error. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.SPSite.PreinitializeServer(SPRequest request) at Microsoft.SharePoint.SPSite.GetSPRequest() at Microsoft.SharePoint.SPSite.get_Request() at Microsoft.SharePoint.SPSite.get_ReadLocked() at Microsoft.ReportingServices.SharePoint.Objects.RSSPImpSite.get_ReadLocked() at Microsoft.ReportingServices.SharePoint.Server.SharePointServiceHelper.<>c__DisplayClass4.b__3() at Microsoft.ReportingServices.SharePoint.Server.Utility.<>c__DisplayClass5.b__3() at Microsoft.ReportingServices.SharePoint.Objects.RSSPImpSecurity.<>c__DisplayClass1.b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Microsoft.ReportingServices.SharePoint.Objects.RSSPImpSecurity.StaticRunWithElevatedPrivileges(CodeToRunElevated secureCode) at Microsoft.ReportingServices.SharePoint.Server.Utility.RunElevated(CodeToRunElevated code)

This was of very little help. There were no errors in the ULS logs.

Eventually we realised that if we loaded a report from a different site collection in a different content database, then it worked, so this indicated that the problem was not Reporting Services itself.

We backed up the existing content database thinking that we would try a restore from backup.

During the backup, SharePoint lost the reference to the content database and we then had an ‘Orphan’ content database in the farm. (I still don’t know how or why that happened)

This prevented me from re-attaching the content database because the Id already existed.

So I thought I would restore the site collection to another content database. This failed. Then I discovered I could no longer create a new site collection in the web application because it couldn’t enumerate the content database because of a null reference exception. The orphan database….

Then I found this post from Steve Thomas.

This is an extract of his solution:


This is a case of at least 1 orphaned database associated to the problematic web application.

1. Run below powershell command to get GUID of web application.

get-spwebapplication | ? {$_.displayname -eq "Problematic Web Application Name"} | fl

2. Run this SQL query against configuration database.

select ID, Name, CAST (properties as xml) from Objects where ID = 'GUID of webapp from Step 1'

3. The results returned from step 2 will have 1 column with the properties as xml. Click on the results and it should open a new window in SQL Mgmt studio with xml output.

4. Search for the word "m_Databases" in the xml output.

5. Carefully read through the tag that stores the above searched word. You should be able to see fld tags. Find out a tag which has fld tag with value null. This is the orphan database. Its GUID is the xml line above where you found null.

6. Cross verify all databases currently associated with the web application and make sure this database is not getting used.

7. Run below powershell script,


This script will throw an object reference error. Do not worry, it works its magic under the hood.

Try to create a new site collection now and it should work.

Summary: The above problem occurs because if there one entry which has fld value set to null SharePoint thinks that that database is the most suitable one to create new site collections in. But since it is an orphaned database, it is unable to do so and reports the above error in ULS which is repeated every time a new site collection creation request is initiated with through SP user interface or Project Server interface.


This allowed me to clear the Orphan content database and then re-attach the database to SharePoint.

Then everything including reporting services started working.

So thanks (not) SSRS for the helpful error message….

And thanks to Steve for having posted a solution that didn’t require ‘hacking’ the config database.

Friday, July 3, 2015

The user experience of working with business documents across multiple devices with Office 365


I have built a Sway to show the user experience across devices for OneDrive in Office 365. I'd love some feedback. The intended audience is non-technical users and the outcome I am looking for is to generate interest in them changing what they currently do to use this mechanism of working with documents.

Friday, April 24, 2015

Raspberry Pi 2 Wi-Fi setup

I got a Raspberry Pi 2 for my birthday today, so I thought it would be a breeze to get going…..(I should know better)

I bought a kit from Wiltronics which included one of these Wi-Fi adapters (Comfast CF-WU755P)

It was supposed to be plug and play. However, after installing the OS all was good until it came to getting the Wi-Fi adapter to install. It when using the GUI to configure the WiFi in preferences it was not recognised

I spent a couple of hours of trying to work out what was going on, reading lots of posts indicating the drivers were not available without compiling and deploying them.

I ran dmesg and found an entry saying R8188EU: ERROR indicate disassoc

this eventually led me to discover the following post which described the Realtek firmware not being deployed by default in Raspbian

For those like me who aren’t Linux gurus, to install the package you download it, extract it and run the following command:

sudo dpkg -i firmware-realtek_0.43_all.deb

After installing this package, I was then able to see the adapter and configure it to connect.

Now I can get on with installing Node.js as per Andrew Connell’s recent post.

Monday, September 22, 2014

Switching to K2 SmartForms mid project


I have been working with K2 products for more than ten years (since 2003) in various roles. Over that time there have been periods of frustration, especially where I have had to support solutions built by other people where they have used InfoPath and a lot of custom code in the workflows. We didn’t previously license the K2 SmartForms piece of the solution, and I have to admit that I was a little sceptical about how good SmartForms would be and how well it would be able to deliver on the requirements we have.

I’ve also been working with SharePoint since 2003. I am not really sad to see the back of InfoPath. Whilst for simple stuff it seemed good on the surface, so many times it got really complicated. I have also had some custom ASP.Net solutions built by partners which integrate with K2. These have also ended up feeling very complicated and are difficult to support. Also, because they are Full Trust SharePoint solutions, deploying changes is a pain, often requiring out of hours effort.

My initial path

I came to a realisation some months ago that I really wanted to get away from Full Trust solutions. This was partly driven by what is happening around Office 365 and also that ‘SharePoint integrated’ and ‘InfoPath integrated’ K2 solutions will only work in 2010 mode on SharePoint 2013.  This means re-writing the workflow/user interface to use the ‘non-integrated’ approaches. Also, I was pretty fed-up with having to deploy on Sunday mornings…

My experience with building workflow solutions during the past ten years leads me to believe that up to 80% of the effort in the solution is building the user interface.

Given that InfoPath is being discontinued and having looked at what was happening in the industry while at the SharePoint conference in Las Vegas, I decided to have a go at building a solution using HTML5, Bootstrap, Angular JS, Entity Framework, SQL, SharePoint and K2. The user interface for the solution would be primarily client side with some WebAPIs taking care of talking to the back end. The workflow would be in K2 BlackPearl.

The solution I was building was due to be delivered within 3 months. Not only that, we could only work on it part time and still had to do other projects, support and maintenance on the platform.

Using these technologies was a huge learning curve. I spent a lot of time watching the great content on Pluralsight and really quite enjoyed the learning. I had to overcome a number of issues including the fact that the current K2 REST APIs don’t support CORS, so I had to build an intermediary using WebAPI.

I worked on this on and off for about 2 months. All the time the deadline for delivering the project was getting ever closer. In addition, I began to realise how much code I was writing, how many components were involved, and started to worry about how other team members were going to be able to skill up and support the solution. Knowing that I was learning it because I was passionate, I had doubts that others would necessarily share my passion to the same extent. I really didn’t want to get into the situation where I was the only person in the team that could provide support and maintenance for the solution. I also wanted us to be able to deliver changes quickly as the need arose.

A new financial year

After quite a lot of evaluation and with the advent of a new financial year and budget, we decided to purchase K2 SmartForms. One of the things I really liked about the SmartForms solution was that it ran outside of SharePoint. Much as I love SharePoint, being able to abstract the design and execution of the forms to somewhere else, but still integrate with the SharePoint platform as needed was an attractive proposition. This fits in well with potential cloud based solutions for the future.

At this point I evaluated the amount of work remaining on the project using the other technologies and came to the conclusion that the sensible thing was to get SmartForms deployed into our infrastructure as quickly as possible and have a go at using that to build the solution. Whilst I really did like what I was doing with Angular JS etc, I decided that the benefit of the rest of our team being able to maintain and support the solution outweighed the reasons to continue.

Round One

I watched some of the material on K2 University and had a go at building the solution using SmartForms, SmartObjects and Workflow over a period of about eight business days. I was already impressed with how much of the solution I had built in that time with absolutely no code.

Then I worked with a K2 Consultant for an hour to see if I was on the right track. As it happened there were a number of techniques which could be used to make the solution much more elegant so I spent the next week rebuilding it. Whilst a little tedious, it helped to reinforce how to use the tools.

Round Two

Having implemented nearly all of the requested features in an incredibly short space of time, I presented to the stakeholders and got some feedback. They seemed happy with the functionality but a bit disappointed with the way the user interface looked. So now it was time to learn how to build a custom theme and make the forms more attractive.

I laughed when the K2 consultant suggested I hand over the design to our CSS developer. Being a very small team, I ‘handed’ the design to myself and began working through the CSS in Visual Studio.

Using some corporate colours and fonts I ended up with a fairly respectable look and feel and again showed it to the stakeholders. They seemed much happier so we decided to schedule a presentation to the team of people who would be using the solution.

Requirements and scope

In some ways, this process has reminded me a lot of the years when I built Lotus Notes solutions in a very agile fashion. (Now that was a product ahead of its time in my opinion….)

Whilst presenting to the team, new requirements surfaced that had not been identified in previous workshops. I was quite amazed that although the changes were of some substance, I completed them in a matter of about seven working hours.

I couldn’t help but wonder how long it would have taken me if I was making those changes to my custom Angular JS based solution.

Conclusion (so far)

I have genuinely been blown away with how much functionality I have been able to build in such a short period of time with no code at all. This was reinforced by how quickly I was able to make changes to the solution.

During the project, I have been able to use the K2 Package and Deployment tools to deploy between development, staging and production environment. It hasn’t been 100% smooth sailing, but I have been able to overcome any issues I have encountered so far. Generally I am pretty happy with this part of the toolset.

I am still working on a couple of technical infrastructure issues with the K2 support team, but I am sure we’ll sort that out.

In the mean time, I have already built two other solutions with SmartForms to do document approvals in SharePoint libraries. I’ll admit I did write a bit of JavaScript for those ones, but only for the SharePoint custom actions to call the SmartForms to then start the workflow. (We are still on SharePoint 2010)

There is genuine excitement among team members about the possibilities for SmartForms and we are running training for the whole team in October. I believe we will be able to deliver high quality consistent solutions in pretty short time frames and I am looking forward to seeing how things progress over the next six months.

I have transitioned from ‘sceptic’ to ‘convert’ when it comes to SmartForms. Congratulations to the K2 team on creating a really useful product.

The challenge of configuring SharePoint 2013 for Apps

I am in the process of configuring new SharePoint 2013 farms in preparation to move from SharePoint 2010 to SharePoint 2013. I also have K2 BlackPearl and K2 Smartforms (which is brilliant and I shall post separately about).

I need to get the App stuff configured in order to use the new K2 for SharePoint.

I did quite a bit of research on this subject and it is quite complex and there is a lot of material available on the web. I have to admit it has taken several days to get this configured to a point where it seems to be working.

These are some of the posts I referred to;

However, these did not really give me all of the answers I needed. I think I have finally worked it out so I will share some points that helped me.

My scenario is that I have multiple SharePoint web applications which use host headers. I followed the guidance and created new ‘app’ domains for dev, staging and production rather than using sub-domains. These are just entries in our internal DNS for now. Unless we start publishing apps outside the firewall, there doesn’t seem to be any point in registering those domains externally. We generated wild card certificates for each of those domains from our Active Directory infrastructure.

Because I have two wild card certificates, one for SSL for my SharePoint web applications and one for the new App domain, I had to create a second IP address for each of my web front end servers. The DNS was configured so the new domains pointed at the second IP address. (I have seen some posts that Windows Server 2012 has some new capability to use a single IP address, but 2 addresses seemed simpler.)

Then I had to create a SharePoint web app on port 80 with no host header as per Jeremy Thakes post;

Some people have written posts about needing a root site collection to get it to work. However, it wasn’t clear where this needed to be created. In my case, the default SharePoint web app on port 80 does NOT seem to require a root site collection. The web apps that you are deploying to DO require a root site collection. (Because I have not yet restored my 2010 databases, I only had a dummy site collection which was not at the root.)

Then I started getting certificate errors. So now in IIS manager I changed the bindings on the SharePoint Default port 80 web site. I changed this so that ports 80 and 443 both bound to the second IP address and configured the SSL certificate to be the one generated for the apps.

Now I can publish a simple App from Visual Studio 2013 and it loads without errors.

In summary;

  • Create two IP addresses on the WFE, one for SharePoint and one for Apps
  • Configure DNS for the new domain you created for Apps to point to the second IP address on the WFE.
  • Create separate wildcard SSL certificates for SharePoint and for Apps.
  • Create a ‘Default’ SharePoint web application using port 80 and no host headers. (No need to configure it with Alternate Access Mappings to support SSL. No need for a site collection.)
  • In IIS Manager change the bindings for the ‘Default’ SharePoint web site to bind to the IP address designated for the apps. Assign the app wild card certificate to the https entry.
  • Bind the https entry for all of the other SharePoint web sites to the other wild card certificate.
  • Follow the guidance from various other sources to do the App configuration (starting the services, creating the service application etc)
  • Try publishing an app from the template in Visual Studio 2013 and see if it renders correctly and all SSL connections work without errors.



It wouldn’t surprise me if this is not the end of the story. However, I hope this might help someone else get to some of the answers more quickly than I did.

Tuesday, June 3, 2014

Breeze, Angular and Entity Framework 'AutoGeneratedKeyType'

I am building an application with Breeze, Angular, WebAPI2 and Entity Framework. It is a big learning curve, but I am making progress.

This issue had me stumped for a little while. When I tried to create a new entity with the createEntity method in Breeze, I was getting this error:

“Cannot attach an object to an EntityManager without first setting its key or setting its entityType 'AutoGeneratedKeyType' property to something other than 'None'”

Googling suggested that it was because the metadata had not been fetched. However, this turned out not to be the problem.

What actually happened was that I used the database first approach to generate the EDMX in Visual Studio. At one point the ID of my table was not an Identity column. I fixed this and refreshed the EDMX from the database.

What I had not realised was that refreshing did not set the StoreGeneratedPattern property to Identity.


Without that set the metadata returned by the breeze controller was this:


With that set the metadata becomes:


Then I was able to create the entity without the error.

Friday, April 4, 2014

Documents missing from SharePoint document sets

I had an issue the other day where a user reported that all of the documents had ‘disappeared’ from their respective document sets in SharePoint 2010.

Sure enough, when I opened the document sets, no documents were listed. If I created a view which didn’t display folders, I saw that the individual documents were still there.

After some analysis, I discovered that the site owner had changed the Welcome Page for the document set content type. When I changed it back to what it should be, the documents were then visible again.