1

We recently upgraded our C# projects from .NET Framework 4.5.2 to .NET 6.0, and now the line

System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources()

no longer works. As far as I can tell, the class SqlDataSourceEnumerator is just not included in the System.Data assembly for .NET 6.0.

I've looked online for other ways to get available SQL Servers, but all of ones I've found either recommend using SqlDataSourceEnumerator, or SmoApplication.EnumAvailableSqlServers() which relies on it internally.

What other ways are there to get available SQL Servers in our C# code that are compatible with .NET 6.0? We need a solution that returns the same info as before (including Server, Name, Instance, Version, and IsLocal).

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
inejwstine
  • 678
  • 1
  • 10
  • 30
  • 2
    This might provide some insight and possibly a work around: https://stackoverflow.com/questions/67577933/the-name-sqldatasourceenumerator-does-not-exist-in-the-current-context. This might also be a solution: https://stackoverflow.com/a/66437788/6530134 – Timothy G. Aug 18 '22 at 16:37
  • @TimothyG. Thanks, I checked them out. Unfortunately they don't work for .NET 6.0. It's starting to look like it won't be implemented, and that a better solution is just to ask the user to type the server they want to connect to, as suggested in the comments to this question: https://stackoverflow.com/questions/67235214/get-a-list-of-sql-servers-in-net-core Still, if there's any other workable solution, I'd be happy to hear it. – inejwstine Aug 18 '22 at 17:40
  • Maybe try dbatools, which is a Powershell module, you can use `Find-DbaInstance` which uses a number of different methods to find instances https://docs.dbatools.io/Find-DbaInstance.html – Charlieface Aug 19 '22 at 00:24

0 Answers0