Monday, March 19, 2012

ListAvailableSQLServers does not show local instances

Hi all

I am using SQL DMO method ListAvailableSQLServers to get the list of all the SQL server available to the local machine.

For some reason, I get all the servers except the instances installed in the local machine. - The are all started.

Any help?

thanks.

I have seen some issues with latency (some servers may not respond fast enough). Also the server instance may be marked hidden.

Start SQL Computer Manager, right click on the Protocols node of the instance and select Properties. Then see if HideInstance is set to No (if not switch to "No" and restart server).

Also try SQLCMD -L

If you see your local instance then it may be a bug in DMO.

|||Thanks Michiel.

I forgot to say that I am working with SQL 2000. I can't find the SQL Computer Manager. Also i try isql -L and I get only the default instance in my machine and nothing else, i.e., not the other instance and not any of the network SQL servers.

In the SQL Server Service Manager I can see all the available servers.
any help ?|||you can use the registry for search local instances

Example:



//Registry for local
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@."SOFTWARE\Microsoft\Microsoft SQL Server");
String[] instances = (String[])rk.GetValue("InstalledInstances");
if (instances.Length > 0)
{
foreach (String element in instances)
{
String name = "";
//only add if it doesn't exist
if (element == "MSSQLSERVER")
name = System.Environment.MachineName;
else
name = System.Environment.MachineName + @."\" + element;

if (cmbServers.FindStringExact(name) == -1)
cmbServers.Items.Add(name);
}


the complete Code (smo) can you find at http://www.sqldbatips.com/showarticle.asp?ID=45

it works with dmo too

No comments:

Post a Comment