Created
November 29, 2013 19:09
-
-
Save pachecoder/7710506 to your computer and use it in GitHub Desktop.
Get all local network sql instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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