Wednesday, June 30, 2010

SSMS 2008 add-ins: one problem solved

If you Google SQL Server Management Studio Add-Ins, you'll find quite a few articles on writing them for SSMS 2005.  You'll also find people complaining that they can't get them to work in 2008.

I can't add any useful comment on the changes made in assemblies between versions, because I didn't attempt writing an SSMS add-in until I'd already upgraded to 2008.  However, I did encounter one problem right away when I attempted to write an SSMS version of a VS 2010 add-in, as have others.  The boilerplate code in the OnConnect method, which was generated by VS, would fail on this line:

     public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
           _applicationObject = (DTE2)application;                      
           _addInInstance = (AddIn)addInInst;

The error message was “No such interface supported”.

A little poking about, and it became clear that this is because, well, the host application isn't a DTE2 anymore.  It's a SSMS object with a very long name and no obvious connection to the DTE2.  Which is a problem if you need any of the DTE2's properties, as you probably do.  

But the fix is easy.  The addInInst object has a DTE property that is, in fact, of type DTE2!  So all you have to do to get over this speed bump is to change those two assignment statements:

    _addInInstance = (AddIn) addInInst;                                    
    _applicationObject = (DTE2) _addInInstance.DTE;

And carry on from there.


Blogger Steve said...

Ann = My day by day .NET/SQL problem solver...

I had a SSMS 2005 add-on that wasn't working correctly... luckily open source...

Modified the source with your code, recompiled... and BOOSH... 2008 is now back in full effect...


7/01/2010 12:14 AM  
Blogger Ann said...

Well, yay!

7/03/2010 11:47 AM  
Blogger Why Specialize? said...

This post helped me out immensely. I was discouraged and not overly hopeful when I googled 'ssms addin "no such interface"', but you saved me hours of sweat and tears.

Thank you!


12/15/2010 1:22 AM  
Blogger Unknown said...

HI Ann,

I've worked with addins before and have gotten some basic ones working. I'm now using VS2008 to build one for SSMS 2008, but my addin doesn't seem to be getting loaded. The only thing that has changed is that I am now working on a windows 7 machine. Do you happen to know if the registry needs to be set up differently in this case?

1/02/2011 1:53 PM  
Blogger Unknown said...

Got it, it just has to go into HKCU instead of HKLM.

1/03/2011 2:02 AM  

Post a Comment

<< Home