The Managed Metadata Service or Connection is currently not available in SharePoint 2013

Problem

Error in Central Admin when accessing the Managed Metadata service application:

The Managed Metadata Service or Connection is currently not available. The Application Pool or Managed Metadata Web Service may not have been started. Please Contact your Administrator.

 

Error in ULS log:

Failed to get term store for proxy 'Managed Metadata Service'. Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

 

Error in Event viewer:

The Managed Metadata Service 'Managed Metadata Service' is inaccessible.

 

I did investigate many suggested solutions out there, and the most similar description of the scenario I found here:

http://sharepoint-community.net/forum/topics/failed-to-get-term-store-for-proxy-managed-metadata-service

 

Previously I had tried to re-create the service application with the same database, but it failed in the same way. So this pointed me to that the error was within the database, not permissions in Central Admin, AppPool trouble, services etc.

 

As someone mentioned in the discussion above, you might have to create a new database and restore the data. In my case this was on a development environment, so backup/restore you said? Luckily i managed to make a way through this problem without scratching the database for good.

 

Solution

These steps solved the issue for me: 

  1. Go to "Central Administration" and select "Manage service applications".
  2. Select your Managed Metadata service application, in my case with almost that name and the button "Properties":
    1. mms-error-1
  3. Locate the "Database name" and change this one to for example "SP2013_MetaData_NEW". Remember to take a note of the old database name for the next steps:
    1.  mms-error-2
  1. Select "OK" and give it some time. SharePoint now creates a new database for you with the name selected above. When it has completed, try to open the service application (Manage) and it now should open without problems, but as expected with an empty term store.
  2. Go back to the list over service applications and repeat step 2. Now enter the old database name instead, in my case "SP2013_MetaData" and select "OK".
  3. Wait some more an access the service application again (Manage). For me it looked like nothing had changed and I now only saw the new database, but I was missing permissions.
  4. Locate the "Term store administrators" and at least add your admin user here:
    1. mms-error-3
  5. Select "Save" and now with the correct permissions you should have access to the existing Term Store and the service application would be back to normal.

 

Note: before performing these steps I had re-created the service application with the existing database. It can be possible that this was necessary to succeed.