Advertisement

04.15.2008 at 11:17AM PDT, ID: 23324683
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.9

Need SQL Server names and databases

Asked by pandkyon in .Net Editors & IDEs, MS SQL Server, Microsoft Visual Basic.Net

Hi Experts:

   I need a simple way to get the name of SQL servers running on the LAN and Local machine as well as their database names. The code I tried, with no luck (due to complexity) is below.  Does someone know of a better approach?  I'm  using Visual basis 2005 / 2008 Express edition. I need to be able to do this programmatically.

Thanks in advance!
pandkyon




Public Class SqlServer
   
    ' '' <summary>
    ' '' The form of EnumerateServers for all machines in the network.
    ' '' </summary>
    Public Overloads Shared Function EnumerateServers() As ServerInstance()
        Return EnumerateServers("")
    End Function
   
    ' '' <summary>
    ' '' Return a collection of server instance descriptors for all SQL Servers within a network
    ' '' </summary>
    ' '' <param name="computerName">Specify a computer name to target a particular machine</param>
    ' '' <returns>An array of ServerInstance descriptor objects</returns>
    ' '' <remarks>This method translates the DataTable to a list of objects with Intellisense.</remarks>
    Public Overloads Shared Function EnumerateServers(ByVal computerName As String) As ServerInstance()
        Dim tableServers As DataTable = Nothing
        If (computerName.Length = 0) Then
            tableServers = SmoApplication.EnumAvailableSqlServers
        Else
            tableServers = SmoApplication.EnumAvailableSqlServers(computerName)
        End If
        '  Create enough space for all the SQL Server instances.
        Dim list(,) As ServerInstance
        '  Build the list of servers.
        Dim index As Integer = 0
        Do While (index  _
                    <= (tableServers.Rows.Count - 1))
            Dim row As DataRow = tableServers.Rows(index)
            Dim name As String = row("Name").ToString
            Dim server As String = row("Server").ToString
            Dim instance As String = row("Instance").ToString
            Dim clustered As Boolean = row("IsClustered").ToString
            Dim local As Boolean = row("IsLocal").ToString
            Dim entry As ServerInstance = New ServerInstance(name, server, instance, clustered, local)
            list(index) = entry
            index = (index + 1)
        Loop
        Return list
    End Function
   
    Public Class ServerInstance
       
        Private m_name As String = ""
       
        Private m_server As String = ""
       
        Private m_instance As String = ""
       
        Private m_clustered As Boolean
       
        Private m_local As Boolean
       
        Public Sub New(ByVal name As String, ByVal server As String, ByVal instance As String, ByVal clustered As Boolean, ByVal local As Boolean)
            MyBase.New
            m_name = name
            m_server = server
            m_instance = instance
            m_clustered = clustered
            m_local = local
        End Sub
       
        Public Property Name As String
            Get
                Return m_name
            End Get
            Set
                m_name = value
            End Set
        End Property
       
        Public Property Server As String
            Get
                Return m_server
            End Get
            Set
                m_server = value
            End Set
        End Property
       
        Public Property Instance As String
            Get
                Return m_instance
            End Get
            Set
                m_instance = value
            End Set
        End Property
       
        Public Property IsClustered As Boolean
            Get
                Return m_clustered
            End Get
            Set
                m_clustered = value
            End Set
        End Property
       
        Public Property IsLocal As Boolean
            Get
                Return m_local
            End Get
            Set
                m_local = value
            End Set
        End Property
    End Class
End Class
Dim s() As SqlServer.ServerInstance
s = SqlServer.EnumerateServers
cmbServer.Items.Clear
i = 0
Do While (i  _
            <= (s.Length - 1))
    cmbServer.Items.Add(s(i).Name)
    i = (i + 1)
LoopStart Free Trial
[+][-]04.15.2008 at 11:46AM PDT, ID: 21361500

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 11:58AM PDT, ID: 21361633

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 12:03PM PDT, ID: 21361680

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 12:28PM PDT, ID: 21361973

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 12:32PM PDT, ID: 21362013

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 12:45PM PDT, ID: 21362144

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.15.2008 at 12:47PM PDT, ID: 21362160

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .Net Editors & IDEs, MS SQL Server, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: maatthias
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.15.2008 at 12:47PM PDT, ID: 21362167

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628