Results 1 to 8 of 8

Thread: [RESOLVED] Server ComputerName

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Tiruvallur, India
    Posts
    201

    Resolved [RESOLVED] Server ComputerName

    The following code retrieves the local computer name

    Code:
    Public Function MachineName() As String
           Dim ComputerName As String = System.Net.Dns.GetHostName
           Return ComputerName
    End Function
    In client-server environment (LAN) , I want the client side application to retrieve the Server's computer name. How to code it?

  2. #2
    Addicted Member thetimmer's Avatar
    Join Date
    Jan 2014
    Location
    Plano, Texas
    Posts
    243

    Re: Server ComputerName

    I just walked backwards a little from this post and came up with this...

    Code:
      Dim strHostName As String = "www.americanfarmersnetwork.com"
            'string strHostName = "www.microsoft.com";
            ' Get DNS entry of specified host name
            Dim addresses() As IPAddress = Dns.GetHostEntry(strHostName).AddressList
            Dim HostName As IPHostEntry = Dns.GetHostEntry(strHostName)
    
            ' The DNS entry may contains more than one IP addresses.
            ' Iterate them and display each along with the type of address (AddressFamily).
    
            Dim sb As New System.Text.StringBuilder
            For Each address As System.Net.IPAddress In addresses
                sb.AppendLine(String.Format("{0} = {1} ({2}) Retrieved HostName = {3}", strHostName, address.ToString, address.AddressFamily.ToString, HostName.HostName.ToString))
            Next
            MessageBox.Show(sb.ToString)
    _____________
    Tim

    If anyone's answer has helped you, please show your appreciation by rating that answer.
    When you get a solution to your issue remember to mark the thread Resolved.


    reference links

  3. #3
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: Server ComputerName

    I would say it depends how your client-server needs to interact. Is your client going to talk directly to the server, or is your client going to contact a database, etc.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Tiruvallur, India
    Posts
    201

    Re: Server ComputerName

    I need to connect to the Sql server database which is lying in the Server Computer. I use computer_name in the connection string.
    My connection string is something like this....
    Code:
    Dbconstring = "Data Source=" & MachineName() & "\SQLEXPRESS;.....
    To Retrieve ComputerName I use the function as shown in my Post #1. The MachineName() function returns the Local Computer Name.
    If I start my application in the client computer, it has to retrieve the server computer's computer_name.

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Server ComputerName

    This thread is a perfect example of why people should provide a clear explanation of what the want to do and not how.

    Look into to the SQL SMO namespace -
    http://technet.microsoft.com/en-us/l.../hh247097.aspx

    http://technet.microsoft.com/en-us/l.../ms162169.aspx

    within it is EnumAvailableSqlSer ers which will get you what you're looking for.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Tiruvallur, India
    Posts
    201

    Re: Server ComputerName

    @techgnome :
    In order to use the EnumAvailableSqlSer function, i need to add this reference : "Microsoft.SqlServer.Management.Smo"
    Unfortunately I did not find it in my Ref.List. I Browsed to add the requisite .dll file.
    But I'm not able to locate that file either in "C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies folder" or in "C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies folder". Can you please help me to sort it out ? (I use VS2008 with Sql 2005)

  7. #7
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Server ComputerName

    That's because SQL Server objects get loaded into the GAC. Besides, you shouldn't be setting a reference directly to the DLL... you'll find it in the .NET Objects tab, along with all the other basic stuff. You may want to sort by namespace to make it easier to find. But it's there.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2012
    Location
    Tiruvallur, India
    Posts
    201

    Re: Server ComputerName

    The following function does it......

    Code:
    Imports System.Data.Sql
    
    Public Function GetServerList() As String
    
            Dim Server As String = String.Empty
            Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
            Dim table As System.Data.DataTable = instance.GetDataSources()
    
            For Each row As System.Data.DataRow In table.Rows
                Server = String.Empty
                Server = row("ServerName")
                If row("InstanceName").ToString.Length > 0 Then
                    Server = Server & "\" & row("InstanceName")
                End If
                If Server = Environment.MachineName Then Exit For
            Next
            Return Server
            
    End Function
    This may be useful : http://www.mssqltips.com/sqlserverti...ws-powershell/

    Explanation given there goes like this...

    you don't even need to have SMO installed on your client machine to enumerate SQL Server instances across your organization as the .NET Framework already includes ADO.NET 2.0. ADO.NET contains the System.Data.Sql namespace which contains classes that support SQL Server-specific functionality. One of these classes is the SqlDataSourceEnumerator which can be used for enumerating all available instances of SQL Server within your local network
    Last edited by raghavendran; Apr 5th, 2014 at 12:24 PM.

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