Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / August 2004

Tip: Looking for answers? Try searching our database.

How to read data connections in Server Explorer?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Nagel - 30 Jun 2004 06:28 GMT
Hi

I'm using VS.Net 2003.

I was (am) hoping to write an add-in to generate c# code to call stored
procedures. So naturally I want to have a drop down list of the data
connections that are present in the Server Explorer, so that I can choose
one of then, then choose the DB, then choose the stored proc.. you get the
picture.

However, it turns out getting access to the server isn't the easiest thing
in the world. Everything else in Visual Studio seems well documented and
easy to get to (task list, output window etc, etc), but the Server Explorer
seems to be a whole different story.

Naturally, I'm going to need to get the connection strings for each of the
data conenctions. That's why I was hoping to use the (for lack of a better
word) "early-bound" version i.e. use the real Server Explorer
classes/intefaces instead of the UIHierarchy/UIHierarchyItems (not that I
even know if this'll work).

Luckily when Visual Studio was still in beta, there were a few crashes
related to the server explorer, which display call stacks:

"Error Message: Object reference not set to an instance of an object.

Call Stack:  at
Microsoft.VSDesigner.Data.VS.VsConnectionManager.CheckConnectoin(Int32
index, ProviderNameInfo nameInfo)
at
Microsoft.VSDesigner.Data.VS.VsConnectionManager.GetConnectionNameList(Array
List nameList, ProviderNameInfo nameInfo)
at Microsoft.VSDesigner.Data.VS.ConnectionPage.InitInput()
at Microsoft.VSDesigner.Data.VS.ConnectionPage.OnEnterPage(EventArgse)
at Microsoft.VSWizards, WizardPage.RaiseEnterPage()
at Microsoft.VSWizards.WizardForm.NextPage()
at Microsoft.VSWizards.WizardForm.Next_Click(Object sender, EventArgse)"

I did some digging (have to love the registry) and found
Microsoft.VSDesigner.Data.VS.VsConnectionManager is tucked away inside
"C:\Program Files\Microsoft Visual Studio .NET
2003\Common7\IDE\Microsoft.VSDesigner.dll".

So I added that .dll to my project references and VsConnectionManager
doesn't show up in the intellisense or Object Browser. Next step: ildasm. It
turns out that VsConnectionManager is declared as:

.class private auto ansi beforefieldinit VsConnectionManager
      extends [mscorlib]System.Object
{
} // end of class VsConnectionManager

It's private. That doesn't help me.

So now I'm here. Has anyone got any ideas? Cause I'm running out quickly!

Thanks
Greg
Daniel A. Seara - 04 Aug 2004 19:59 GMT
Hi, Guys.
I was in the same problem, and was looking around my disk.
Finnaly, I can find a way to solve tyhe problem.
I know so much of you wirte code in C#, but I'm a VB fanatic, so here is my
solution. (I believe it is too easy to translate it to C#).
HTH
---------
  Dim xConList As Xml.XmlNodeList
  Private Function FindConString(ByVal ConnectionName As String) As String
     If xConList Is Nothing Then
        ' load from the definition file
        Dim x As New Xml.XmlDocument
        Try

x.Load(String.Format("{0}\Microsoft\VisualStudio\7.1\ServerExplorer\DefaultV
iew.SEView",
System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
)
           'Get the Elements definig Conections
           xConList = x.GetElementsByTagName("a1:DataViewNode")
        Catch ex As Exception
           Throw ex
        End Try
        If xConList Is Nothing OrElse xConList.Count = 0 Then
           Throw New System.IO.FileLoadException
        End If
     End If
     ' Follow the elements one by one
     For Each xOne As Xml.XmlNode In xConList
        Dim sName As String = ""
        Dim sCOn As String = ""
        For Each xChild As Xml.XmlNode In xOne.ChildNodes
           ' One Child, called Label, contains the same string used in the
Server Explorer to name the connection
           If xChild.Name = "Label" Then
              sName = xChild.InnerText
              'this one contains the Connection String
           ElseIf xChild.Name = "ConnectString" Then
              sCOn = xChild.InnerText
           End If
        Next
        'So when found the name searched, you have the ConnectionString
here!
        If sName = ConnectionName Then
           Return sCOn
        End If
     Next
  End Function
--------------------------
Daniel A. Seara
INETA Speaker
MVP .Net

> Hi
>
[quoted text clipped - 26 lines]
> index, ProviderNameInfo nameInfo)
> at

Microsoft.VSDesigner.Data.VS.VsConnectionManager.GetConnectionNameList(Array
> List nameList, ProviderNameInfo nameInfo)
> at Microsoft.VSDesigner.Data.VS.ConnectionPage.InitInput()
[quoted text clipped - 23 lines]
> Thanks
> Greg
Predrag Tomasevic - 05 Aug 2004 12:27 GMT
Hah ;)) nice solution...

tnx Daniel

> Hi, Guys.
> I was in the same problem, and was looking around my disk.
[quoted text clipped - 110 lines]
> > Thanks
> > Greg
Nimai Malle - 27 Aug 2004 17:10 GMT
Predrag,
I was looking for this information because I wanted to do the same
thing as you did: Create an OleDbCommand based of a stored procedure
definition.  Did you complete your add-in?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.