Results 1 to 3 of 3

Thread: [RESOLVED] Get the Server name from DNS name

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Get the Server name from DNS name

    Hi,

    I need to obtain the sql server name of a server based on its DNS name.

    I have looked at the system.net methods

    Code:
    servername = Dns.GetHostEntry("ReportServer")
                    servername = Dns.GetHostByName("ReportServer")
    But they return ReportServer.Group.Local rather than the sql server name SQL0001.

    Is there another method I could try?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Get the Server name from DNS name

    1. Add a reference to Microsoft.SqlServer.Smo to your project
    2. Call the EnumAvailableSqlServers method to get available SQL servers.
    Code:
    Dim serverName As String = "ReportServer"
    Dim sqlServers As DataTable = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers(False)
    For Each row As DataRow In sqlServers.Rows
        If row("Server").ToString.ToLower = serverName.ToLower Then
              MessageBox.Show(row("Name").ToString)
        End If
    Next
    This method call will take a few seconds to complete depending on how large your network is and since it is a blocking method, you might want to run it using a background thread if you want the UI stays responsive.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] Get the Server name from DNS name

    Thanks that worked, after I finally figured out I actually had to reference it rather than just imports. It is not ideal being a little slow but it seems the best alternative.

    The only other idea was to actually create a connection to the server then get the servername from the current connection.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width