Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Getting the Different Istances of SQL SERVER

Author  Topic 

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2007-03-31 : 07:00:57
Hi All,

Is there any way I can get the different Instances of SQL SERVER of Single SERVER Machine.

On my notebook, i got SQL SERVER 2000 and SQL SERVER 2005 Express edition installed, i want to get the instance name of both the SERVER and populate it in the front end.

I am using Visual C# 2005.

Here is my function which i have written so far.


public static bool GetServerList(ref ArrayList _arlstServer, ref string _strErrMsg)
{
DataTable _dsServers = SmoApplication.EnumAvailableSqlServers();
try
{
foreach (DataRow _drServers in _dsServers.Rows)
{
if (_drServers["Instance"] != null && _drServers["Instance"].ToString().Length > 0)
{
string strName = _drServers["Instance"].ToString();
_arlstServer.Add(strName);
}
}
Server localServer = new Server();

if (localServer.Name != "")
_arlstServer.Add(localServer.Name);

_strErrMsg = string.Empty;
return true;
}
catch (Exception ex)
{
_strErrMsg = ex.Message.ToString();
return false;
}
finally
{
_dsServers = null;
}
}

with the above code, i m only able to get the instance of SQL SERVER 2000.

I am using the following namespaces.
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

Any Guidance will be appreciated.

Thanks..


Chirag

http://chirikworld.blogspot.com/
   

- Advertisement -