How do I get a list of SQL Servers available on my network?

I'm trying this but I'm not sure how to proceed. Can you give me a hand?

SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; DataTable table = instance.GetDataSources(); foreach (var row in table.Rows) { foreach (var column in table.Columns) { ddlPublisherServer.Items.Add(???); } }

Where ??? = SQL Server Name.

How would I go about extracting the sql server name from the table?

I'm working in ASP .NET with C#.


Well, if wanted to see all available information, you can iterate over the columns available:

DataTable dt = SqlDataSourceEnumerator.Instance.GetDataSources(); foreach (DataRow dr in dt.Rows) { foreach (DataColumn col in dt.Columns) { Console.WriteLine("{0,-15}: {1}", col.ColumnName, dr[col]); } Console.WriteLine(); }

Which would show something like:

ServerName : COMPUTER1 InstanceName : SQLEXPRESS IsClustered : No Version : 9.00.4035.00

So, to answer your question:


Full Code:

DataTable table = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources(); foreach (DataRow server in table.Rows) { ddlPublisherServer.Items.Add(server[table.Columns["ServerName"]].ToString()); }


  • Save website uploads in a subdomain
  • 3.0.0.M1: SSL - Invalid keystore format
  • Msvcr71.dll Msvcp71.dll missing
  • Change device language on Android 6.0 (Android M)
  • How to log in to an HTTPS website with Jsoup?
  • Primefaces :radioButton inside a ui:repeat
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • how does System.Web.HttpRequest::PathInfo work?
  • ListItem.Attributes.Add not working
  • pyodbc doesn't report sql server error
  • Breaking out column by groups in Pandas
  • Unable to get column index with table.getColumn method using custom table Model
  • Groovy: Unexpected token “:”
  • Swing - Get new component under mouseReleased
  • Custom validator control occupying space even though display set to dynamic
  • Replace value with Factor in r data.table
  • How to clear text inside text field when radio button is select
  • How to access EntityManager inside Entity class in EJB3
  • Repeat a vertical line on every page in Report Builder / SSRS
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Launch Runnable Jar from Web Start
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • PHP - How to update data to MySQL when click a radio button
  • Counter field in MS Access, how to generate?
  • Get object from AWS S3 as a stream
  • Cross-Platform Protobuf Serialization
  • Validaiting emails with Net.Mail MailAddress
  • Do I've to free mysql result after storing it?
  • php design question - will a Helper help here?
  • json Serialization in asp
  • How do you join a server to an Active Directory (domain)?
  • Angular 2 constructor injection vs direct access
  • coudnt use logback because of log4j
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • File not found error Google Drive API
  • UserPrincipal.Current returns apppool on IIS
  • Converting MP3 duration time
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How do I use LINQ to get all the Items that have a particular SubItem?