我有代码来查找 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;
}
它工作正常(如果找到 SQL Server),但不幸的是它找不到 sql Express。
有人有想法吗?
提前谢谢你