Reputation: 4261
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
Upvotes: 0
Views: 3410
Reputation: 6602
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)
SQL Server 2000 provides information for the SqlDataSourceEnumerator internally. SQL Server 2005, however, provides the information through the use of an external Windows service named SQL Browser. This service is enabled by default, but administrators may turn it off or disable it, making the server instance invisible to this class. This service applies only to SQL Server 2005, and has no effect on the behavior of SQL Server 2000.
By default, the SQL Server Browser service is not enabled for SQL Server Express. SQL Server Browser can be initially configured using the Surface Area Configuration Tool and managed using SQL Server Configuration Manager.
Upvotes: 7