Skip to content

Instantly share code, notes, and snippets.

@pachecoder
Created November 29, 2013 19:09
Show Gist options
  • Save pachecoder/7710506 to your computer and use it in GitHub Desktop.
Save pachecoder/7710506 to your computer and use it in GitHub Desktop.
Get all local network sql instances.
//using System.Data.Sql;
public List<string> GetLocalNetworkSqlInstances()
{
SqlDataSourceEnumerator instances = SqlDataSourceEnumerator.Instance;
List<string> listInstance = new List<string>();
DataTable dt = instances.GetDataSources();
listInstance.Clear();
foreach (DataRow item in dt.Rows)
{
if (item.ItemArray[1] == DBNull.Value)
{
listInstance.Add((string) item.ItemArray[0]);
}
else
{
listInstance.Add(item.ItemArray[0] + @"\" + item.ItemArray[1]);
}
}
return listInstance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment