How to list available instances of SQL Servers using SMO in C#?

前端 未结 4 712
小鲜肉
小鲜肉 2020-11-30 15:12

Can anybody explain me what I wrong I am doing in the following piece of code:

DataTable dt=SmoApplication.EnumAvailableSqlServer(true);
Server sr = new Serv         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 15:48

    Take a look at the following links they may be helpful:

    • Enumerate SQL Server Instances in C#, Using ODBC
    • How to get a list of available SQL Servers using C# (MSDN)
    • Populating a list of SQL Servers

    Alternatively you could change your code to this:

    DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
    if (dt.Rows.Count > 0)
    {
        foreach (DataRow dr in dt.Rows)
        {
            Console.WriteLine(dr["Name"]);
        }
    }
    

    Hope this solves your problem.

提交回复
热议问题