I use following code to get all existing sql servers.

using Microsoft.SqlServer.Management.Smo;  

DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
             
  if (dt.Rows.Count > 0)
   {
           cmb_servers.Items.Clear();

           foreach (DataRow dr in dt.Rows)
           {
                 cmb_servers.Items.Add(dr["Name"]);
           }
                   
   }

In first attempt it's not loading any servers at all but in second it is.

I know it's quite difficult to believe but it is happening, may be any unknown mistake from my side or anything else.

Any suggestions upon that?

Recommended Answers

All 4 Replies

No mistake, from the documentation:

"The computer running the instance SQL Server might not receive responses to the EnumAvailableSqlServers method in a timely manner. The returned list might not show all the available instances of SQL Server on the network. When you call the EnumAvailableSqlServers method in subsequent tries, more servers might become visible on the network."

No mistake, from the documentation:

"The computer running the instance SQL Server might not receive responses to the EnumAvailableSqlServers method in a timely manner. The returned list might not show all the available instances of SQL Server on the network. When you call the EnumAvailableSqlServers method in subsequent tries, more servers might become visible on the network."

Thanks 'Momerath' for your quick reply,

I got u but what should I do?

Do I need a loop that will search servers in fixed no of attempts?

But it might also failed?

Not much you can do about it. You can check if you get zero results, pause a second then try again if you want.

Not much you can do about it. You can check if you get zero results, pause a second then try again if you want.

Thanks, am also planning to do that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.