问题
I have some old VB.Net code that I have used for years that retrieves SQL instances. It has worked perfectly for a number of years (through SQL Server 2008, 2012, now 2014). But I installed Windows 10 a week ago and (this is the first time I've used the code since) now it's not returning any rows in the table whatsoever. And yes (I've read the other related items) SQL Browsing service is running).
The code being used is directly out of MSDN (where I originally found it)...
Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim table As System.Data.DataTable = instance.GetDataSources()
DisplayData(table)
Me.LoginName.Enabled = True
Me.LoginPassword.Enabled = True
And, yes, before anyone asks, I checked the contents of table
in debug mode at execution. The rows count=0
.
Does anyone know if this is a Windows 10 issue and/or have any thoughts on what to do to get the instances now?
Thanks in advance for any assistance/advice!
回答1:
There seems to be problem with Windows 10: https://connect.microsoft.com/VisualStudio/feedback/details/1633740/system-data-sql-sqldatasourceenumerator-doesnt-work-on-windows-10-with-net-framework-4-x
You could apply a workaround and directly read the instance names from the registry.
RegistryKey lm= RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
RegistryKey key = lm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");
if(key != null){
foreach (string s in key.GetValueNames())
Console.WriteLine("localhost\\" + s);
key.Close();
}
key = lm.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL");
if(key != null){
foreach (string s in key.GetValueNames())
Console.WriteLine("localhost\\" + s);
key.Close();
}
lm.Close();
回答2:
Just did tests with EnumAvailableSqlServers in Windows 10 Pro new Insider Preview Build 10565 using a small c# test app and it seems to work now. SqlDataSourceEnumerator is supposed to be used by EnumAvailableSqlServers, so this method also should now work.
回答3:
Old question, I know. I just ran into the same problem and ended up here though.
I found out through other sources that you need to turn on SQL Server Browser service. Tested with SqlDataSourceEnumerator and ODBC32, both now work.
来源:https://stackoverflow.com/questions/31977719/get-sql-server-instances-in-windows-10