Search code examples
c#sqlsql-serverdatabaseenumerate

How would one List the Databases in a SQL Server, not by query, but by c# call?


From this: Enumerate all running databases

One can list the servers on the network, but once one selects one of those servers, how does one then list the DB's in that server, by using a similar method as above?

Thanks!


Solution

  • You can use SQL Management Objects (SMO). First, you'd use the SmoApplication class and one of its EnumAvailableSqlServers methods to find the server.

    Once you've found the server you want, you'd create a Server instance, and then use its Databases property.