Click here to Skip to main content
12,548,135 members (47,046 online)
Click here to Skip to main content
Add your own
alternative version


4 bookmarked

Locate SQL Server Instances on the Local Network

, 30 Apr 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
This is an alternative for "Locate SQL Server instances on the local network"


This articles shows how to retrieve a list of PCs on the local network which are running MS SQL Server, and gets information about the instances, such as server name, instance name, version, and databases.

This article is an alternative to the article: Locate SQL Server instances on the local network[^]


To get a list of the nearby SQL Servers is as simple as typing "osql /L" on a command prompt. But getting them programmatically, for use inside an application, is a bit trickier. The most common use for this would be to create a connection string building form in managed code, which will be the subject of my next article.

Socket^ socket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Dgram, ProtocolType::Udp);

ArrayList^ servers = gcnew ArrayList();
array<Byte>^ msg= {0x02};
IPEndPoint^ ep = gcnew IPEndPoint(IPAddress::Broadcast, 1434);
socket->SendTo( msg, SocketFlags::None, ep );

Using the Code

Everything is packaged in the class SqlServerInfo. It has one static method, Seek(), which gets the information about the SQL Server instances on the network, and returns an array of SqlServerInfo objects.

int main(array<System::String ^> ^args)
  array<SqlServerInfo^>^ lst = SqlServerInfo::Seek();

  for(int i = 0; i < lst->Length; i++)

   SqlServerInfo^ name_srv = lst[i];
    Console::WriteLine( name_srv );
  return 0;
InstanceName is typically "MSSQLSERVER", which is the default if it isn't given a specific name at installation. Version should be "" for SQL Server 2000. And TcpPort will typically be 1433.


        13-Dec 2005 - v 1.0 Initial release.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Constantin Chumak
Software Developer
Canada Canada
20+ years as a developer : Assembly, C, C++ and C#, Fortran, TSQL, ASP.Net, ActionScript,..

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161021.1 | Last Updated 30 Apr 2012
Article Copyright 2012 by Constantin Chumak
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid