问题
I want to get list of Sql server instance that are existing in local network with the name of computer that it belongs to.
question2:if a user select every instance of SqlExpress ,i want to get the path that it becomed installed, i mean for example "C:\Program Files\Microsoft SQL Server.....".
thanks alot.
回答1:
Check this MSDN page
EDIT: for future reference, here is the relevant code.:
using System.Data.Sql;
class Program
{
static void Main()
{
// Retrieve the enumerator instance and then the data.
SqlDataSourceEnumerator instance =
SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
// Display the contents of the table.
DisplayData(table);
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
private static void DisplayData(System.Data.DataTable table)
{
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
}
Console.WriteLine("============================");
}
}
}
来源:https://stackoverflow.com/questions/5297021/how-can-get-the-list-of-sql-server-instanceor-sqlexpress-that-are-installed-an