none
GetDataSources does not work anymore in .NET Framework 4.6 RRS feed

  • Question

  • In C#, the following code does not work anymore after installing .NET Framework 4.6.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ListSQLServers
    {
        class Program
        {
            static void Main(string[] args)
            {
                string server;
                int i = 0;
    
                System.Data.DataTable servers = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
    
                for (i=0; i<servers.Rows.Count; i++)
                {
                    if ((servers.Rows[i]["InstanceName"] as string) != null)
                    {
                        server = (servers.Rows[i]["ServerName"] + "\\" + servers.Rows[i]["InstanceName"]);
                    }
                    else
                    {
                        server = servers.Rows[i]["ServerName"].ToString();
                    }
    
                    Console.WriteLine(server);
                }
            }
        }
    }
    The call to GetDataSources returns almost immediately and does not return any SQL servers.

    Is this a bug in .NET Framework 4.6?

    In .NET Framework 4.5 it works fine.
    • Edited by Strat65 Wednesday, August 5, 2015 2:52 PM
    Wednesday, August 5, 2015 7:58 AM

Answers

All replies

  • Hi Strat65,

    I've checked in MSDN about SqlDataSourceEnumerator.Instance Property

    In Version Information

    .NET Framework

    Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

    .NET Framework Client Profile

    Supported in: 4, 3.5 SP1

    Based on above, it should support .Net Framework 4.6.

    Please make sure there is no Windows Firewall on or no effects of third-party software.

    Please also note that from MSDN document:

    Due to the nature of the mechanism used by SqlDataSourceEnumerator to locate data sources on a network, the method will not always return a complete list of the available servers, and the list might not be the same on every call. If you plan to use this function to let users select a server from a list, make sure that you always also supply an option to type in a name that is not in the list, in case the server enumeration does not return all the available servers. In addition, this method may take a significant amount of time to execute, so be careful about calling it when performance is critical.

    Best regards,

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Thursday, August 6, 2015 2:40 AM
    Thursday, August 6, 2015 2:37 AM
  • Hi Kristin,

    I tested this problem on several systems where .NET Framework 4.5 was installed. It works fine with this version. After I upgrade to version .NET Framework 4.6 on these systems it stops working. So i do not think it has to do with firewalls or other third-party software. These systems are freshly installed and fully updated Windows 7 and Windows 8 systems. It also does not work on Windows 10, which seems logically to me as .NET Framework 4.6 is an integrated part of this OS.

    Best regards,

    Hans Kluijtmans

    Thursday, August 6, 2015 4:28 PM
  • Hi Kristin,

    I tested this problem on several systems where .NET Framework 4.5 was installed. It works fine with this version. After I upgrade to version .NET Framework 4.6 on these systems it stops working. So i do not think it has to do with firewalls or other third-party software. These systems are freshly installed and fully updated Windows 7 and Windows 8 systems. It also does not work on Windows 10, which seems logically to me as .NET Framework 4.6 is an integrated part of this OS.

    Best regards,

    Hans Kluijtmans

    @Hans Kluijtmans

    I would suggest that you can report bugs at connect.microsoft.com/VisualStudio  I will help vote it.    After you submit this bug, please help post the link here. Thanks for your support and cooperation.    


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 10, 2015 5:26 AM
  • Dear Kristin,

    I reported the bug. Here's the link:

    https://connect.microsoft.com/VisualStudio/Feedback/Details/1649626

    (sorry I had to insert the link like this, because the forum did not accept the html link)

    I noticed that more people reported the same bug so it may be considered a duplicate.

    Best regards,

    Hans Kluijtmans.

    Monday, August 10, 2015 9:32 AM
  • Dear Kristin,

    I reported the bug. Here's the link:

    https://connect.microsoft.com/VisualStudio/Feedback/Details/1649626

    (sorry I had to insert the link like this, because the forum did not accept the html link)

    I noticed that more people reported the same bug so it may be considered a duplicate.

    Best regards,

    Hans Kluijtmans.

    @Hans Kluijtmans

    Since you said that more people reported the same bug. Could you find the link in the Connect? If yes, please also post here.

    What are these bugs' status now?  If it's still active, this may take some time to wait for Microsoft to fix this bug.  Appreciate your patience and thanks for your understanding.

    I have already voted.

    Happy coding.

    Regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.




    • Edited by Kristin Xie Monday, August 10, 2015 9:41 AM
    Monday, August 10, 2015 9:40 AM
  • Hi Kristin,

    Here some similar active issues I found on connect:

    1572915
    1582568
    1598047
    1627543
    1633740
    1648065

    Best regards,

    Hans Kluijtmans.

    Monday, August 10, 2015 10:18 AM