how can get the list of Sql Server instance(or SqlExpress) that are installed and exist in local network

跟風遠走 提交于 2019-12-12 17:10:05

问题


I want to get list of Sql server instance that are existing in local network with the name of computer that it belongs to.

question2:if a user select every instance of SqlExpress ,i want to get the path that it becomed installed, i mean for example "C:\Program Files\Microsoft SQL Server.....".

thanks alot.


回答1:


Check this MSDN page

EDIT: for future reference, here is the relevant code.:

using System.Data.Sql;

class Program
{
  static void Main()
  {
    // Retrieve the enumerator instance and then the data.
    SqlDataSourceEnumerator instance =
      SqlDataSourceEnumerator.Instance;
    System.Data.DataTable table = instance.GetDataSources();

    // Display the contents of the table.
    DisplayData(table);

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
  }

  private static void DisplayData(System.Data.DataTable table)
  {
    foreach (System.Data.DataRow row in table.Rows)
    {
      foreach (System.Data.DataColumn col in table.Columns)
      {
        Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
      }
      Console.WriteLine("============================");
    }
  }
}


来源:https://stackoverflow.com/questions/5297021/how-can-get-the-list-of-sql-server-instanceor-sqlexpress-that-are-installed-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!