Enumerate SQL data sources
-
Hi, How can I enumerate SQL data sources in my domain using C#? I found MS KnowledgeBase article 310107, but I can't get the code to even compile. Thanks, Royce
Well this is more simple than you think. It's merely a SQL Query that you need to use:
select name from master..sysdatabases
Will select all the data sources from the current SQL instance. So create a SQL command, and use this as the query, and your result will be a table with datasources. Hope this helps. Gidon -
Well this is more simple than you think. It's merely a SQL Query that you need to use:
select name from master..sysdatabases
Will select all the data sources from the current SQL instance. So create a SQL command, and use this as the query, and your result will be a table with datasources. Hope this helps. GidonGidon, Thanks for your help. I am a newbie to SQL (as you might have guessed), so maybe I misstated my problem. I am equating "data source" to "server", as described in the help for the SqlConnection class: Data Source -or- Server -or- Address: The name or network address of the instance of SQL Server to which to connect. So I want to find all of the servers on the current domain. Royce
-
Gidon, Thanks for your help. I am a newbie to SQL (as you might have guessed), so maybe I misstated my problem. I am equating "data source" to "server", as described in the help for the SqlConnection class: Data Source -or- Server -or- Address: The name or network address of the instance of SQL Server to which to connect. So I want to find all of the servers on the current domain. Royce
Well the truth I'm not sure. You can maybe loop through all the computers in the domain, and try to make a sqlconnection, if it succeeds you know there is a SQL server on that computer in the domain. I did a quick google search and found this thread about listing computers in the domain using .NET http://www.dotnet247.com/247reference/msgs/32/161278.aspx[^] Gidon
-
Gidon, Thanks for your help. I am a newbie to SQL (as you might have guessed), so maybe I misstated my problem. I am equating "data source" to "server", as described in the help for the SqlConnection class: Data Source -or- Server -or- Address: The name or network address of the instance of SQL Server to which to connect. So I want to find all of the servers on the current domain. Royce
See this article: http://www.codeproject.com/cs/database/LocatingSql.asp[^] -- LuisR
Luis Alonso Ramos Intelectix - Chihuahua, Mexico Not much here: My CP Blog!
-
Hi, How can I enumerate SQL data sources in my domain using C#? I found MS KnowledgeBase article 310107, but I can't get the code to even compile. Thanks, Royce
Using SQLDMO is by far the easiest way to do this. It is a pain to distribute though because you need to distribute half a dozen com dlls and some of them need to go into specific folders. I did one of these recently and it took me nearly a day to find the documentation on distributing DMO correctly. Jon