Thursday, March 13, 2008

Getting the built in data browser to work in 2005 and 2008

When we last left our hero he had just got the global data menu working under '05 and '08.  Next step was use of the table browser.  Here's a shot of it working with SQL Server data.  Now there is no particular reason to use this data browser instead of writing our own other than it's just less work and it has a nice look and feel.



On the surface this looks pretty easy.  After a little digging I discovered that this command binding will add a "Show Table Data" menu option and bring up a nice OleDB-based data browser under VS 2005.
<CommandBinding name="Browse_Data" guid="501822E1-B5AF-11d0-B4DC-00A0C91506EF" cmdid="12384"
                handler="Microsoft.VisualStudio.DataTools.DBPackage.VDT_OLEDB_CommandHandler_TableTools">
  <Parameter value="Open"/>
</CommandBinding>

The problem, of course, is that this doesn't work under VS 2008.  The handler under VS 2008 is implemented by an object with the guid of 884DD964-5327-461f-9F06-6484DD540F8F.  My first approach was to define two of these bindings and no matter which version of VS ran one of them would fail (and not add any menu item) while the other would succeed.  VS doesn't like that.  Apparently the guid and cmdId together form a key and you get a key added twice error. Hmmm
My good buddy Stephen at Microsoft offered up the solution of overriding the GetDataViews method of DataViewSupport and tweaking the XML that is returned.  It turns out that he was spot on.  I set all the handlers in the XML file to be proper for VS 2005, changed my DataViewSupport derived class to now use the no parameter constructor base, and then overrode the GetDataViews method like so.
public override Stream GetDataViews() { string xmlName = "MySql.Data.VisualStudio.DDEX.MySqlDataViewSupport.xml"; Assembly executingAssembly = Assembly.GetExecutingAssembly(); Stream stream = executingAssembly.GetManifestResourceStream(xmlName); StreamReader reader = new StreamReader(stream); string xml = reader.ReadToEnd(); reader.Close(); // if we are running under VS 2008 then we need to switch out a couple // of command handlers DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE; if (dte.Version.StartsWith("9")) xml = xml.Replace ("Microsoft.VisualStudio.DataTools.DBPackage.VDT_OLEDB_CommandHandler_TableTools", "884DD964-5327-461f-9F06-6484DD540F8F"); MemoryStream ms = new MemoryStream(xml.Length); StreamWriter writer = new StreamWriter(ms); writer.Write(xml); writer.Flush(); ms.Position = 0; return ms; }




I won't bother with showing you a pic of it working in MySQL because it looks just like the other pic.  But, then again, that's the point.  :)

12 comments:

  1. I have found two interesting sources http://fileshunt.com and http://filesfinds.com and would like to give the benefit of my experience to you.

    ReplyDelete
  2. thanks for sharing your ideas i really appreciate it!great post!

    ReplyDelete
  3. busby seo test postJanuary 19, 2009 at 12:04 PM

    nice post, thank you

    ReplyDelete
  4. Friendster LayoutsJanuary 24, 2009 at 6:26 AM

    Great info! I have a blog with the same interest/topic. Hope we can exchange links.

    Best Regards!

    Ginj

    ReplyDelete
  5. thanks for info, great post

    ReplyDelete
  6. Kampanye Damai Pemilu Indonesia 2009February 20, 2009 at 5:05 PM

    Woah, that's cool stuff, many thanks for you..

    ReplyDelete
  7. This is a great collection of CSS-related links

    ReplyDelete
  8. Hits Tech GadgetsMarch 6, 2009 at 2:43 PM

    my aboriginal move is like this, I access was to ascertain two of these bindings and no amount which adaptation of VS ran one of them would abort (and not add any card item) while the added would succeed. VS doesn't like that. Apparently the guid and cmdId calm anatomy a key and you get a key added alert error

    ReplyDelete
  9. What a nice post! Thank you for posting an informative article.

    ReplyDelete
  10. Online Stock BrokerageSeptember 10, 2009 at 4:48 PM

    I digged this for more news from you.



    Regards and respect
    Worker

    ReplyDelete
  11. Super Website...

    [...] that is the end of this article. Here you’ll find some sites that we think you’ll appreciate, just click the links over[...]...

    ReplyDelete