i have code to find list of sqlserver
public static string[] GetSQLServerList()
{
SqlDataSourceEnumerator dse = SqlDataSourceEnumerator.Instance;
DataTable dt = dse.GetDataSources();
if (dt.Rows.Count == 0)
{
return null;
}
string[] SQLServers = new string[dt.Rows.Count];
int f = -1;
foreach (DataRow r in dt.Rows)
{
string SQLServer = r["ServerName"].ToString();
string Instance = r["InstanceName"].ToString();
if (Instance != null && !string.IsNullOrEmpty(Instance))
{
SQLServer += "\\" + Instance;
}
SQLServers[System.Math.Max(System.Threading.Interlocked.Increment(ref f), f - 1)] = SQLServer;
}
Array.Sort(SQLServers);
return SQLServers;
}
it work fine (if found SQL Server), but unfortunately it can not find sql Express.
anybody have an idea ?
Thanks you in advance
You need to enable the SQL Browser service for a SQL server instance to be browsable.
SQL Express does not have this enabled by default.
References:
Enumerating Instances of SQL Server (ADO.NET)
Using SQL Server Browser