473,785 Members | 3,417 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get a list of SQL Server Instances?

I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
from http://www.sqldev.net/misc/ListSQLSvr.htm

I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))

SQL Browser Service: not running

- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing

SQL Browser Service: running

- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS
Dec 19 '07 #1
8 12201
Additional Info:

If I try to add connection in Server Explorer of VS2008,

- SQL Browser Service: not running
only see MSSQLSERVER

- SQL Browser Service: running
only see mymachine\SQLEX PRESS

So, this behavior is same as GetDataSource or SMO.

I hope someone can explain this strange behavior and tell me how I should
get the list of SQL Server Instances in a VB.Net application.
"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
from http://www.sqldev.net/misc/ListSQLSvr.htm

I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))

SQL Browser Service: not running

- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing

SQL Browser Service: running

- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS

Dec 19 '07 #2
On Dec 19, 12:33 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Additional Info:

If I try to add connection in Server Explorer of VS2008,

- SQL Browser Service: not running
only see MSSQLSERVER

- SQL Browser Service: running
only see mymachine\SQLEX PRESS

So, this behavior is same as GetDataSource or SMO.

I hope someone can explain this strange behavior and tell me how I should
get the list of SQL Server Instances in a VB.Net application.

"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
fromhttp://www.sqldev.net/misc/ListSQLSvr.htm
I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))
SQL Browser Service: not running
- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing
SQL Browser Service: running
- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS- Hide quoted text -

- Show quoted text -
Here's some C# code I wrote for a dialog box component that mimics the
one from SQL Management Studio... It seems to work for me:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Data.Sql ;
using Microsoft.Win32 ;
using Microsoft.SqlSe rver.Management .Smo;

namespace FireAnt.Control s.Database
{
[Serializable()]
internal class ServerInstance : IComparable,
IComparable<Ser verInstance>, IComparable<str ing>
{
private string server;
private string instance;
private Version version;

private static readonly string LocalServer = Dns.GetHostName
().ToUpper ();
private const string ServerInstanceR egistryKey = "SOFTWARE\
\MICROSOFT\\MIC ROSOFT SQL SERVER\\INSTANC E NAMES\\SQL";

#region Constructors
public ServerInstance () : this ( string.Empty ) { }
public ServerInstance ( string server ) : this ( server,
string.Empty ) { }
public ServerInstance ( string server, string instance ) :
this ( server, instance, "0.0" ) { }
public ServerInstance ( string server, string instance, string
version ) : this ( server, instance, new Version ( version ) ) { }
public ServerInstance ( string server, string instance,
Version version )
{
this.server = server;
this.instance = instance;
this.version = version;
}
#endregion

#region Properties
public string Server
{
get { return this.server; }
}

public string Instance
{
get { return this.instance; }
}

public Version Version
{
get { return this.version; }
}
#endregion

#region Overrides
public override string ToString ()
{
StringBuilder displayString = new StringBuilder
( this.Server );

// add the instance name if we have one
if ( !string.IsNullO rEmpty ( this.Instance ) )
{
displayString.A ppendFormat ( "\\{0}", this.Instance );
}

// add the version if it is a valid one
if ( this.Version.Ma jor != 0 )
{
displayString.A ppendFormat ( " ({0}.{1})",
this.Version.Ma jor, this.Version.Mi nor );
}

return displayString.T oString ();
}

public override bool Equals ( object obj )
{
if ( obj == null || !( obj is ServerInstance ) )
return false;
return ( this.ToString () == obj.ToString () );
}

public override int GetHashCode ()
{
return this.ToString ().GetHashCode ();
}
#endregion

#region Operators
public static implicit operator string ( ServerInstance
instance )
{
return instance.ToStri ng ();
}
#endregion

public static List<ServerInst anceGetLocalSer verList ()
{
List<ServerInst ancelocalServer s = new
List<ServerInst ance();

RegistryKey registryKey = Registry.LocalM achine.OpenSubK ey
( ServerInstanceR egistryKey );
if ( registryKey != null )
{
using ( registryKey )
{
foreach ( string instanceName in
registryKey.Get ValueNames () )
{
localServers.Ad d ( new ServerInstance
( LocalServer, instanceName ) );
}
}
}

return localServers;
}

public static List<ServerInst anceGetNetworkS erverList ()
{
List<ServerInst ancenetworkServ ers = new
List<ServerInst ance();

using ( DataTable dataSources =
SqlDataSourceEn umerator.Instan ce.GetDataSourc es () )
{
foreach ( DataRow dataSource in dataSources.Row s )
{
networkServers. Add ( new ServerInstance (
(string)dataSou rce["ServerName "],
Convert.IsDBNul l
( dataSource["InstanceNa me"] ) ? string.Empty :
(string)dataSou rce["InstanceNa me"],
Convert.IsDBNul l ( dataSource["Version"] ) ?
"0.0" : (string)dataSou rce["Version"] ) );
}
}

return networkServers;
}
#region IComparable Members

public int CompareTo ( object obj )
{
if ( obj == null || !(obj is ServerInstance ))
return -1;
else
return this.ToString ().CompareTo ( obj.ToString () );

}

#endregion

#region IComparable<Ser verInstanceMemb ers

public int CompareTo ( ServerInstance other )
{
return this.ToString ().CompareTo ( other.ToString () );
}

#endregion

#region IComparable<str ingMembers

public int CompareTo ( string other )
{
return this.ToString ().CompareTo ( other );
}

#endregion
}
}

Anyway, maybe you can make use of this - convert it to vb or
whatever :)

--
Tom Shelton
Dec 20 '07 #3
Hi Tom,

Thanks for the code and will try it. If I understand your coding correctly,
you're checking local registries for local instances and using GetDataSource
for network instances. My current coding is just using GetDataSource.

The issue that I'm experiencing seems to be the one mentioned in here:
http://forums.microsoft.com/MSDN/Sho...98078&SiteID=1
I think your coding may not work for this known issue.
Peter

"Tom Shelton" wrote:
On Dec 19, 12:33 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Additional Info:

If I try to add connection in Server Explorer of VS2008,

- SQL Browser Service: not running
only see MSSQLSERVER

- SQL Browser Service: running
only see mymachine\SQLEX PRESS

So, this behavior is same as GetDataSource or SMO.

I hope someone can explain this strange behavior and tell me how I should
get the list of SQL Server Instances in a VB.Net application.

"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
fromhttp://www.sqldev.net/misc/ListSQLSvr.htm
I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))
SQL Browser Service: not running
- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing
SQL Browser Service: running
- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS- Hide quoted text -
- Show quoted text -

Here's some C# code I wrote for a dialog box component that mimics the
one from SQL Management Studio... It seems to work for me:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Data.Sql ;
using Microsoft.Win32 ;
using Microsoft.SqlSe rver.Management .Smo;

namespace FireAnt.Control s.Database
{
[Serializable()]
internal class ServerInstance : IComparable,
IComparable<Ser verInstance>, IComparable<str ing>
{
private string server;
private string instance;
private Version version;

private static readonly string LocalServer = Dns.GetHostName
().ToUpper ();
private const string ServerInstanceR egistryKey = "SOFTWARE\
\MICROSOFT\\MIC ROSOFT SQL SERVER\\INSTANC E NAMES\\SQL";

#region Constructors
public ServerInstance () : this ( string.Empty ) { }
public ServerInstance ( string server ) : this ( server,
string.Empty ) { }
public ServerInstance ( string server, string instance ) :
this ( server, instance, "0.0" ) { }
public ServerInstance ( string server, string instance, string
version ) : this ( server, instance, new Version ( version ) ) { }
public ServerInstance ( string server, string instance,
Version version )
{
this.server = server;
this.instance = instance;
this.version = version;
}
#endregion

#region Properties
public string Server
{
get { return this.server; }
}

public string Instance
{
get { return this.instance; }
}

public Version Version
{
get { return this.version; }
}
#endregion

#region Overrides
public override string ToString ()
{
StringBuilder displayString = new StringBuilder
( this.Server );

// add the instance name if we have one
if ( !string.IsNullO rEmpty ( this.Instance ) )
{
displayString.A ppendFormat ( "\\{0}", this.Instance );
}

// add the version if it is a valid one
if ( this.Version.Ma jor != 0 )
{
displayString.A ppendFormat ( " ({0}.{1})",
this.Version.Ma jor, this.Version.Mi nor );
}

return displayString.T oString ();
}

public override bool Equals ( object obj )
{
if ( obj == null || !( obj is ServerInstance ) )
return false;
return ( this.ToString () == obj.ToString () );
}

public override int GetHashCode ()
{
return this.ToString ().GetHashCode ();
}
#endregion

#region Operators
public static implicit operator string ( ServerInstance
instance )
{
return instance.ToStri ng ();
}
#endregion

public static List<ServerInst anceGetLocalSer verList ()
{
List<ServerInst ancelocalServer s = new
List<ServerInst ance();

RegistryKey registryKey = Registry.LocalM achine.OpenSubK ey
( ServerInstanceR egistryKey );
if ( registryKey != null )
{
using ( registryKey )
{
foreach ( string instanceName in
registryKey.Get ValueNames () )
{
localServers.Ad d ( new ServerInstance
( LocalServer, instanceName ) );
}
}
}

return localServers;
}

public static List<ServerInst anceGetNetworkS erverList ()
{
List<ServerInst ancenetworkServ ers = new
List<ServerInst ance();

using ( DataTable dataSources =
SqlDataSourceEn umerator.Instan ce.GetDataSourc es () )
{
foreach ( DataRow dataSource in dataSources.Row s )
{
networkServers. Add ( new ServerInstance (
(string)dataSou rce["ServerName "],
Convert.IsDBNul l
( dataSource["InstanceNa me"] ) ? string.Empty :
(string)dataSou rce["InstanceNa me"],
Convert.IsDBNul l ( dataSource["Version"] ) ?
"0.0" : (string)dataSou rce["Version"] ) );
}
}

return networkServers;
}
#region IComparable Members

public int CompareTo ( object obj )
{
if ( obj == null || !(obj is ServerInstance ))
return -1;
else
return this.ToString ().CompareTo ( obj.ToString () );

}

#endregion

#region IComparable<Ser verInstanceMemb ers

public int CompareTo ( ServerInstance other )
{
return this.ToString ().CompareTo ( other.ToString () );
}

#endregion

#region IComparable<str ingMembers

public int CompareTo ( string other )
{
return this.ToString ().CompareTo ( other );
}

#endregion
}
}

Anyway, maybe you can make use of this - convert it to vb or
whatever :)

--
Tom Shelton
Dec 20 '07 #4
Peter,

The SQLDataSourceEn umerator class may be what you need.

Kerry Moorman
"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
from http://www.sqldev.net/misc/ListSQLSvr.htm

I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))

SQL Browser Service: not running

- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing

SQL Browser Service: running

- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS

Dec 20 '07 #5
On Dec 19, 7:46 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Hi Tom,

Thanks for the code and will try it. If I understand your coding correctly,
you're checking local registries for local instances and using GetDataSource
for network instances. My current coding is just using GetDataSource.

The issue that I'm experiencing seems to be the one mentioned in here:http://forums.microsoft.com/MSDN/Sho...98078&SiteID=1
I think your coding may not work for this known issue.

Peter

"Tom Shelton" wrote:
On Dec 19, 12:33 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Additional Info:
If I try to add connection in Server Explorer of VS2008,
- SQL Browser Service: not running
only see MSSQLSERVER
- SQL Browser Service: running
only see mymachine\SQLEX PRESS
So, this behavior is same as GetDataSource or SMO.
I hope someone can explain this strange behavior and tell me how I should
get the list of SQL Server Instances in a VB.Net application.
"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
fromhttp://www.sqldev.net/misc/ListSQLSvr.htm
I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))
SQL Browser Service: not running
- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing
SQL Browser Service: running
- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS- Hide quoted text -
- Show quoted text -
Here's some C# code I wrote for a dialog box component that mimics the
one from SQL Management Studio... It seems to work for me:
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Data.Sql ;
using Microsoft.Win32 ;
using Microsoft.SqlSe rver.Management .Smo;
namespace FireAnt.Control s.Database
{
[Serializable()]
internal class ServerInstance : IComparable,
IComparable<Ser verInstance>, IComparable<str ing>
{
private string server;
private string instance;
private Version version;
private static readonly string LocalServer = Dns.GetHostName
().ToUpper ();
private const string ServerInstanceR egistryKey = "SOFTWARE\
\MICROSOFT\\MIC ROSOFT SQL SERVER\\INSTANC E NAMES\\SQL";
#region Constructors
public ServerInstance () : this ( string.Empty ) { }
public ServerInstance ( string server ) : this ( server,
string.Empty ) { }
public ServerInstance ( string server, string instance ) :
this ( server, instance, "0.0" ) { }
public ServerInstance ( string server, string instance, string
version ) : this ( server, instance, new Version ( version ) ) { }
public ServerInstance ( string server, string instance,
Version version )
{
this.server = server;
this.instance = instance;
this.version = version;
}
#endregion
#region Properties
public string Server
{
get { return this.server; }
}
public string Instance
{
get { return this.instance; }
}
public Version Version
{
get { return this.version; }
}
#endregion
#region Overrides
public override string ToString ()
{
StringBuilder displayString = new StringBuilder
( this.Server );
// add the instance name if we have one
if ( !string.IsNullO rEmpty ( this.Instance ) )
{
displayString.A ppendFormat ( "\\{0}", this.Instance );
}
// add the version if it is a valid one
if ( this.Version.Ma jor != 0 )
{
displayString.A ppendFormat ( " ({0}.{1})",
this.Version.Ma jor, this.Version.Mi nor );
}
return displayString.T oString ();
}
public override bool Equals ( object obj )
{
if ( obj == null || !( obj is ServerInstance ) )
return false;
return ( this.ToString () == obj.ToString () );
}
public override int GetHashCode ()
{
return this.ToString ().GetHashCode ();
}
#endregion
#region Operators
public static implicit operator string ( ServerInstance
instance )
{
return instance.ToStri ng ();
}
#endregion
public static List<ServerInst anceGetLocalSer verList ()
{
List<ServerInst ancelocalServer s = new
List<ServerInst ance();
RegistryKey registryKey = Registry.LocalM achine.OpenSubK ey
( ServerInstanceR egistryKey );
if ( registryKey != null )
{
using ( registryKey )
{
foreach ( string instanceName in
registryKey.Get ValueNames () )
{
localServers.Ad d ( new ServerInstance
( LocalServer, instanceName ) );
}
}
}
return localServers;
}
public static List<ServerInst anceGetNetworkS erverList ()
{
List<ServerInst ancenetworkServ ers = new
List<ServerInst ance();
using ( DataTable dataSources =
SqlDataSourceEn umerator.Instan ce.GetDataSourc es () )
{
foreach ( DataRow dataSource in dataSources.Row s )
{
networkServers. Add ( new ServerInstance (
(string)dataSou rce["ServerName "],
Convert.IsDBNul l
( dataSource["InstanceNa me"] ) ? string.Empty :
(string)dataSou rce["InstanceNa me"],
Convert.IsDBNul l ( dataSource["Version"] ) ?
"0.0" : (string)dataSou rce["Version"] ) );
}
}
return networkServers;
}
#region IComparable Members
public int CompareTo ( object obj )
{
if ( obj == null || !(obj is ServerInstance ))
return -1;
else
return this.ToString ().CompareTo ( obj.ToString () );
}
#endregion
#region IComparable<Ser verInstanceMemb ers
public int CompareTo ( ServerInstance other )
{
return this.ToString ().CompareTo ( other.ToString () );
}
#endregion
#region IComparable<str ingMembers
public int CompareTo ( string other )
{
return this.ToString ().CompareTo ( other );
}
#endregion
}
}
Anyway, maybe you can make use of this - convert it to vb or
whatever :)
--
Tom Shelton- Hide quoted text -

- Show quoted text -
Actually, it seems to work fine here. I have two instances on this
box - the default (it shows up as MSSQLSERVER), and then an named
instance os sql express - SQLEXPRESS.

I also have default on another PC, and it is found also. Basically,
mine matches whats in the management studio dialog - except that in
management studio, the default local instance doesn't show
MSSQLSERVER, mine does.

--
Tom Shelton
Dec 20 '07 #6
Hi Kerry,

I have also tried SQLDataSourceEn umerator class and have the same problem.

Peter

"Kerry Moorman" wrote:
Peter,

The SQLDataSourceEn umerator class may be what you need.

Kerry Moorman
"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
from http://www.sqldev.net/misc/ListSQLSvr.htm

I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))

SQL Browser Service: not running

- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing

SQL Browser Service: running

- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS
Dec 20 '07 #7
Hi Tom,

If you run your coding on another PC, does it show the default instance and
express instance of your box? If I understand correctly, the problem only
occurs if you have the default instance and express on the same PC. If you
run your coding on your box, it works fine since you also check local
registry. But if you run your coding on another PC, I think you will get
only the Express instance on your box. I hope I'm wrong.

"Tom Shelton" wrote:
On Dec 19, 7:46 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Hi Tom,

Thanks for the code and will try it. If I understand your coding correctly,
you're checking local registries for local instances and using GetDataSource
for network instances. My current coding is just using GetDataSource.

The issue that I'm experiencing seems to be the one mentioned in here:http://forums.microsoft.com/MSDN/Sho...98078&SiteID=1
I think your coding may not work for this known issue.

Peter

"Tom Shelton" wrote:
On Dec 19, 12:33 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Additional Info:
If I try to add connection in Server Explorer of VS2008,
- SQL Browser Service: not running
only see MSSQLSERVER
- SQL Browser Service: running
only see mymachine\SQLEX PRESS
So, this behavior is same as GetDataSource or SMO.
I hope someone can explain this strange behavior and tell me how I should
get the list of SQL Server Instances in a VB.Net application.
"Peter" wrote:
I'm trying to get a list of SQL Server Instances thru a VB.NET application.
I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe
fromhttp://www.sqldev.net/misc/ListSQLSvr.htm
I run all of them on a Windows XP Professional 64bit machine which has 2
instances: mymachine\SQLEx press (Express Edition) and MSSQLSERVER (Developer
Edition (64bit))
SQL Browser Service: not running
- GetDataSource or SMO returns MSSQLSERVER
- ListSQLSvr returns nothing
SQL Browser Service: running
- GetDataSource or SMO or ListSQLSvr returns mymachine\SQLEX PRESS- Hide quoted text -
- Show quoted text -
Here's some C# code I wrote for a dialog box component that mimics the
one from SQL Management Studio... It seems to work for me:
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Net;
using System.Data;
using System.Data.Sql ;
using Microsoft.Win32 ;
using Microsoft.SqlSe rver.Management .Smo;
namespace FireAnt.Control s.Database
{
[Serializable()]
internal class ServerInstance : IComparable,
IComparable<Ser verInstance>, IComparable<str ing>
{
private string server;
private string instance;
private Version version;
private static readonly string LocalServer = Dns.GetHostName
().ToUpper ();
private const string ServerInstanceR egistryKey = "SOFTWARE\
\MICROSOFT\\MIC ROSOFT SQL SERVER\\INSTANC E NAMES\\SQL";
#region Constructors
public ServerInstance () : this ( string.Empty ) { }
public ServerInstance ( string server ) : this ( server,
string.Empty ) { }
public ServerInstance ( string server, string instance ) :
this ( server, instance, "0.0" ) { }
public ServerInstance ( string server, string instance, string
version ) : this ( server, instance, new Version ( version ) ) { }
public ServerInstance ( string server, string instance,
Version version )
{
this.server = server;
this.instance = instance;
this.version = version;
}
#endregion
#region Properties
public string Server
{
get { return this.server; }
}
public string Instance
{
get { return this.instance; }
}
public Version Version
{
get { return this.version; }
}
#endregion
#region Overrides
public override string ToString ()
{
StringBuilder displayString = new StringBuilder
( this.Server );
// add the instance name if we have one
if ( !string.IsNullO rEmpty ( this.Instance ) )
{
displayString.A ppendFormat ( "\\{0}", this.Instance );
}
// add the version if it is a valid one
if ( this.Version.Ma jor != 0 )
{
displayString.A ppendFormat ( " ({0}.{1})",
this.Version.Ma jor, this.Version.Mi nor );
}
return displayString.T oString ();
}
public override bool Equals ( object obj )
{
if ( obj == null || !( obj is ServerInstance ) )
return false;
return ( this.ToString () == obj.ToString () );
}
public override int GetHashCode ()
{
return this.ToString ().GetHashCode ();
}
#endregion
#region Operators
public static implicit operator string ( ServerInstance
instance )
{
return instance.ToStri ng ();
}
#endregion
public static List<ServerInst anceGetLocalSer verList ()
{
List<ServerInst ancelocalServer s = new
List<ServerInst ance();
RegistryKey registryKey = Registry.LocalM achine.OpenSubK ey
( ServerInstanceR egistryKey );
if ( registryKey != null )
{
using ( registryKey )
{
foreach ( string instanceName in
registryKey.Get ValueNames () )
{
localServers.Ad d ( new ServerInstance
( LocalServer, instanceName ) );
}
}
}
return localServers;
}
public static List<ServerInst anceGetNetworkS erverList ()
{
List<ServerInst ancenetworkServ ers = new
List<ServerInst ance();
using ( DataTable dataSources =
SqlDataSourceEn umerator.Instan ce.GetDataSourc es () )
{
foreach ( DataRow dataSource in dataSources.Row s )
{
networkServers. Add ( new ServerInstance (
(string)dataSou rce["ServerName "],
Convert.IsDBNul l
( dataSource["InstanceNa me"] ) ? string.Empty :
(string)dataSou rce["InstanceNa me"],
Convert.IsDBNul l ( dataSource["Version"] ) ?
"0.0" : (string)dataSou rce["Version"] ) );
}
}
return networkServers;
}
#region IComparable Members
public int CompareTo ( object obj )
{
if ( obj == null || !(obj is ServerInstance ))
return -1;
else
return this.ToString ().CompareTo ( obj.ToString () );
}
#endregion
#region IComparable<Ser verInstanceMemb ers
public int CompareTo ( ServerInstance other )
{
return this.ToString ().CompareTo ( other.ToString () );
}
#endregion
#region IComparable<str ingMembers
public int CompareTo ( string other )
{
return this.ToString ().CompareTo ( other );
}
#endregion
}
}
Anyway, maybe you can make use of this - convert it to vb or
whatever :)
--
Tom Shelton- Hide quoted text -
- Show quoted text -

Actually, it seems to work fine here. I have two instances on this
box - the default (it shows up as MSSQLSERVER), and then an named
instance os sql express - SQLEXPRESS.

I also have default on another PC, and it is found also. Basically,
mine matches whats in the management studio dialog - except that in
management studio, the default local instance doesn't show
MSSQLSERVER, mine does.

--
Tom Shelton
Dec 20 '07 #8
On Dec 19, 9:06 pm, Peter <Pe...@discussi ons.microsoft.c omwrote:
Hi Tom,

If you run your coding on another PC, does it show the default instance and
express instance of your box? If I understand correctly, the problem only
occurs if you have the default instance and express on the same PC. If you
run your coding on your box, it works fine since you also check local
registry. But if you run your coding on another PC, I think you will get
only the Express instance on your box. I hope I'm wrong.

Hmmm, you may be right - I'll have to try that from the other machine
when I get a minute.

--
Tom Shelton
Dec 20 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5775
by: L Robbins | last post by:
I am a newcomer to PHP and am writing a script which dynamically creates instances of a class with names like $object1, $object2, etc.. I now want my script to be able to list all of the objects which are instances of a specific class -- but I haven't been able to find any code which does this in the online PHP references I've consulted. Given that the names of the objects are predictable, it would be possible for me to write some code...
0
1230
by: List Server | last post by:
IMail List Server for Windows NT, Ipswitch, Inc. -------------------------------------------------------------------- Valid Commands are: To subscribe to a list, send a mail message to "imailsrv" at this address with the following in the body of the message: subscribe listname your_full_name
1
2717
by: Zicco Fen | last post by:
We have windows clients and a DB2 UDB database on an AIX box. In Windows, if we use the Control Center, add the system, and expand on the tree, we can see the list of instances on the system and the list of the databases. How do I do that using command line from the windows client machine? Thanks.
1
7559
by: karim | last post by:
My computer (connected to a domain) is having trouble connecting to the local MSDE when using 'local' or '(local)' as server name. The only way I can connect to server through Visual Studio or DTS in Enterprise manager is when using domainname\localcomputername format. Also when I try to install the starter kits from asp.net, the installer in each kit fails to find sql server instances. I am pretty sure it's related to fact the installer is...
2
9865
by: jayuya | last post by:
How can i check in java script if a asp.net radio button list server control is selected? I have some custom javascript function in the client side that needs to run but I don't see the way to see if user selected or not one of the options.... thanks, jayuya
2
3407
by: christof | last post by:
I've asked on sql.programming, but got no answer: Is there a way to get all the SQL Server instances with SQL SMO from a remote computer? I got few instances on some remote IP and how to list them, how to pass to the function this address - could it be done at all? Second question:
0
1249
by: dmlinliverpool | last post by:
I am running VS.net 2005 Express and Sql Server 2005 Express. The DB and VS are both on the same PC. I cannot connect to a database from within VS. In Database Explorer I click Connect To Database to add an existing DB to the DB Explorer. In the dialog box I navigate to the MDF of my DB and after I click Test Connection it takes some 20 seconds before giving the error ..."Error
3
2059
by: manstey | last post by:
how do I detect a change in a list of class instances? from copy import deepcopy class CaListOfObj(list): """ subclass of list """ def __init__(self, *args, **kwargs): list.__init__(self, *args, **kwargs) class CaClass(object):
1
1396
benchpolo
by: benchpolo | last post by:
Can you please explain in Laymans term the definition of SQL Server instances? Bec someone from our non-technical dept is requeting to create s SQL Server Instance in 2000. Thanks.
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.