获取数据库服务名称

public static List<string> GetSqlServerNames()
{
List<string> serverNames = new List<string>();
DataTable table = SqlClientFactory.Instance.CreateDataSourceEnumerator().GetDataSources();
foreach (DataRow dr in table.Rows)
{
string serverName = string.Format("{0}\\{1}", dr["ServerName"], dr["InstanceName"]);
serverNames.Add(serverName);
}
return serverNames;
}

posted @ 2013-06-17 21:21  RattanyiXu  阅读(202)  评论(0编辑  收藏  举报