Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# : Problem with SqlDataSourceEnumerator.Instance.GetDataSources()

Tags:

c#

I am trying to enlist all the SQL Server instances (Local and Network) in a ComboBox by using the following code:

        DataTable dt = null;
        dt = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
        foreach (DataRow dr in dt.Rows)
        {
          ComboBox1.Items.Add(dr[0].ToString() + "\\" + dr[1].ToString());
        }

It works fine on Windows XP 32 Bit, Windows 7 64 Bit by enlisting all of my local and network sql server instances in the combo, but when this piece of code runs on Windows 7 32bit (All Professional version) it takes long time to fetch the instance details and ultimately fails to enlist even a single instance (which i believe due to some sort of TimeOut). The data table does not have even a single row in this case. Thus I want to ask following questions:

  1. Does this problem is platform specific or OS specific?

  2. Is it really due to slow network speed/ large no. of server instances on the network?

  3. Is there any alternate to this requirement which is not platform or framework dependent as

    SmoApplication.EnumAvailableSqlServers(false); // local and Network SQL instances

    is framewrok dependent.

I have got at least 17-20 Network Server of SQL Server which I expect this function to return. Hence I can not understand how this could happen? I am encountering this problem precisely on Windows 7 32bit (Professional version).

Thank you

Hemant Jaiswal

like image 881
Hemant Jaiswal Avatar asked Nov 14 '22 22:11

Hemant Jaiswal


1 Answers

This problem is more 'network specific' rather than 'OS' or 'platform'. It may work of not work depending on network settings of the machine, network configuration, firewalls etc. This function is known for it's instability, it also can skip some servers (even if list of servers is not empty). So, my reccomendation would be to check network/firewall setting of the machines.

like image 175
Petr Abdulin Avatar answered May 20 '23 16:05

Petr Abdulin