Announcement

Collapse
No announcement yet.

Locating SQL servers

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Locating SQL servers

    Hi,
    I have used both ODBC and DMO functions to locate SQL servers on our network but both are really slow and not allways complete. I have found a bit of code that just uses a "simple" UDP broadcast to get the server responses but I can't get it working, thought I would just be able to modify the echo client in samples but got no responses at all.

    c# code
    Code:
    Socket socket = new Socket(AddressFamily.InterNetwork, 
                  SocketType.Dgram, ProtocolType.Udp );
    //  For .Net v 1.1 the options are cumbersome & hidden.
    
        socket.SetSocketOption(SocketOptionLevel.Socket, 
                  SocketOptionName.Broadcast, 1);
        socket.SetSocketOption(SocketOptionLevel.Socket, 
                  SocketOptionName.ReceiveTimeout, 3000);
        
    //  For .Net v 2.0 it's a bit simpler
    
    //  socket.EnableBroadcast = true;    // for .Net v2.0
    
    //  socket.ReceiveTimeout = 3000;     // for .Net v2.0
    
    
    IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 1434);
    byte[] msg = new byte[] { 0x02 };
    socket.SendTo(msg, ep);
    complete code is here http://www.codeproject.com/KB/databa...l_servers.aspx


    sorry URL not working for me today

    Can anyone point me in the right direction ?

    N.
    Last edited by Neil J Hosgood; 10 Aug 2009, 07:48 PM.

  • #2
    I tend to shell to the osql command line app that comes with the sql server client tools, and pipe it to a file

    e.g.

    osql -L

    This will list all local and networked sql servers and their instance names that are broadcasting.

    Comment

    Working...
    X