This error can be encountered while viewing an InfoPath form in the browser. In most cases, the problem can be solved by reading through the following blogpost.
In my case, the state service was enabled and the service application was correctly associated with the webapplication. I solved this by deleting the 'corrupt' state service database, creating a new one and attaching the new database to the farm - all these steps can be done with some Powershell commands.
Related article: Manage the State Service (SharePoint Server 2010)