We recently had a situation with our System Center 2012 Virtual Machine Manager (VMM) that literally frustrated the crap out of me.  Don’t take that wrong, the product didn’t really cause the frustration instead it was the mis-use of the libraries in 2012 that did.  You see, you live & learn and when we originally setup our Development Cloud in 2012, we hacked together the libraries to allow the most flexibility. You should read that as saying – we didn’t RTFM before we embarked on creating the libraries.  

After months & months of using VMM 2012, we finally figured out (or this is where I should confuse you with tense and say that, I, figured it out) how to setup libraries correctly for a cloud.  This is what we (Microsoft) thought most administrators would do before they created a cloud & made libraries available.  The breakdown of clouds, libraries, and 2012 I will save for another day but for now let me just explain the nightmare that will exist when you have physical objects (e.g. iso’s, VHDs, etc.) in the VMM database yet the physical files themselves are gone. 

The result:  Your library will fail to refresh.  Again.  Again.  And did I mention again? 

Detecting the Problem:  Error 801 VMM cannot find {Object Type} {Object ID}

It starts with investigating you Jobs wonderbar in the VMM Administration Console.  During the typical 60 minute refresh cycle (60 is the default, but configurable), you will see an entry that says your refresh failed.  In our case, we had a tester who was wanting to utilize a ISO they’d uploaded to the Self-service Library though they couldn’t use it as VMM wasn’t aware of it due to the refresh failing.  Wow.  (In this case, it was easier to use Hyper-V Manager to attach and we did so to unblock the tester but that would kill this blog post Smile

Error801VMObjectIdErrorVMM

Well, this is easy…let’s remove the object right?  Let’s do it…

Thus, I chased down trying to remove any instance of the VM object in question and I was able to do so by doing the following in SQL Management Studio:

  1. Connect to the VirtualManagerDB using credentials with sysadmin permissions
  2. Click New Query
  3. Select the VirtualManagerDB and enter the following:
Select * from dbo.tbl_WLC_VMInstance where ObjectID = '{Enter Object Id from Jobs Details}'

This should return any instances of this object and the next thing to do is the following:

Delete from dbo.tbl_WLC_VMInstance where ObjectId = '{Enter Object ID}'

This will return that it completed successfully and then re-run the select command and you will see 0 instances and you are set.  Below are complete examples of the commands used -

VMObjectIdVMInstance

DeleteVMObjectIdVMInstance

The last step is to try and refresh the library shares and see if they complete.

Refresh Fails:  What do I do now?

The downside of doing this is that you’ve successfully removed the object yet you don’t have the library happy at this point.  I was *unsuccessful* at determining how to correct this and thus I went the hard route and RTFM (e.g. read documentation) and set things up a bit different like I mentioned above.  The real fun began when you try and remove the library using the VMM Administration Console

Unfortunately, it turns out the library when in this state is also un-removable and there is no method I could determine to correct this.  The error returned was the same as above-

Error801VMObjectId

It turns out, I couldn’t remove the library even though I had removed all VM objects in VMM (trust me, I might have missed ‘em in the DB but not for the lack of trying).

Nuke Library in Database, I say…

As a last resort, you can always go straight to the database.  This is not recommended for the faint of heart and I suggest you backup your VMM database immediately – now – before you continue forward.  Let’s get on with forcibly removing your library share.

To remove a library share from your VMM instance that is un-manageable, do the following:

NOTE:  Please stop your VMM Service before proceeding

  1. Open SQL Management Studio
  2. Select New Query & connect to the VirtualManagerDB
  3. The first thing to do is find the LibShareId for the share you’d like to remove.  To do this, use the following command:
Select Name, LibraryShareId from dbo.tbl_IL_LibraryShare

The result set returns to you a list of all the library shares known to this VMM server.  The key thing you want is the Library Share ID which is used in the upcoming steps.

image

 

Deleting References & Library Share:  Let’s do this

If you immediately attempt to delete the library share, you will violate a constraint in the VirtualManagerDB between two tables – LibraryShare & PhysicalObject.  To allow the removal, you need to remove the reference to the Library Share found above it in the PhysicalObject’s table using the following command:

Select * from dbo.tbl_WLC_PhysicalObject where LibShareId = '{Insert Library Share ID from step 3}'

image

 
If you move forward, you will notice no references and you should not have any problems with the constraint.   
You will now be able to delete the reference in the dbo.tbl_IL_LibraryShare table:
Delete from dbo.tbl_WLC_PhysicalObject where LibShareId = '{Insert Library Share ID from step 3}

image

You will now be able to confirm that under Library > Library Servers > {Server}  you will no longer have the share you just removed.  We monitored the server for several days but the first thing we did was refresh the library and watched it successfully complete across all our shares.

Summary

This was painful on our end.  It took over 2 weeks to figure out what is going on and make the appropriate changes to allow folks to get back to work.  I personally take credit for screwing up a few things when we set the cloud up and I will not do that again but in the end the work required to figure out, and clean up, was above and beyond anything done before by us in VMM.  Because of this, you’ve hopefully learned a few things around how to go hunting in the VirtualManagerDB for objects and hopefully removing them.  Happy hunting…don’t forget to backup your VMM Database.

Enjoy!

Thanks,

-Chris