1

I wanted to create an extension to Visual Studio that displays the name of the database selected in Server Explorer. I've tried the following C# code.

    var dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
    EnvDTE.UIHierarchy serverExplorer = dte.ToolWindows.GetToolWindow("Server Explorer");
    object[] items = serverExplorer.SelectedItems as object[];
    MessageBox.Show(items[0].ToString());

I need to find the name and credentials of the selected database in Server Explorer.

Also, items[0].ToString() returns System._ComObject. But I can find the name of the database at items[0] -> DynamicView -> Name.

Could anyone help me to find the name and credentials of the selected database?

Thanks in advance.

Akshara
  • 211
  • 1
  • 9
  • 1
    It would be a very, very, very insecure system if you could steal passwords like this. Why do you assume you need to retrieve the passwords like this? If you want to create an extension, you *don't* want the tool window, you want the *server object itself* – Panagiotis Kanavos Mar 01 '18 at 09:19
  • Sorry for the mistake. I just wanted the database name to be displayed. – Akshara Mar 01 '18 at 09:23

0 Answers0