Get Sql instances in .Net

zequion 171 Reputation points

How can I retrieve a DataTable from Sql Server instances in .Net? In the .Net Framework it was done this way:

    SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;  
    DataTable table = instance.GetDataSources();  
    string ServerName = Environment.MachineName;  
    foreach (DataRow row in table.Rows){  Console.WriteLine (ServerName + "\\" + row["InstanceName"].ToString());  }  

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,468 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hui Liu-MSFT 46,961 Reputation points Microsoft Vendor

    Hi,@zequion.Welcome to Microsoft Q&A.

    In .NET, you could use the SqlDataSourceEnumerator class by adding the the Microsoft.Data.Sql package.

    You can right click on your project to select Manage NuGet Packages... and search Microsoft.Data.Sql on Browse page to install the Microsoft.Data.Sql package in Visual Studio.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments