Skip to content

Instantly share code, notes, and snippets.

@jrotello
Created July 7, 2013 14:27
Show Gist options
  • Save jrotello/5943638 to your computer and use it in GitHub Desktop.
Save jrotello/5943638 to your computer and use it in GitHub Desktop.
Enumerate over all available SQL Server instances.
DataTable data = SqlDataSourceEnumerator.Instance.GetDataSources();
foreach(DataRow row in data.Rows) {
string server = row["ServerName"].ToString();
string instance = row["InstanceName"].ToString();
if (!string.IsNullOrWhiteSpace(instance)) {
server += "\\" + instance;
}
Console.WriteLine(server);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment