How to Find All SQL Server Instance Running in Local Network c#
来源:互联网 发布:web域名注册免费 编辑:程序博客网 时间:2024/06/05 23:41
Create new class its name to GetInstance and write this below code on GetInstance class.
using System.Collections;
using System.Data;
namespace SqlServer
{
public class GetInstance
{
public static ArrayList GetInstanceName()
{
try
{
SqlServerList SqlSL = new SqlServerList();
SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
DataTable table = instance.GetDataSources();
ArrayList list = new ArrayList();
foreach (DataRow row in table.Rows)
{
SqlSL = new SqlServerList();
SqlSL.ServerName = row[0].ToString();
SqlSL.InstanceName = row[1].ToString();
SqlSL.IsClustered = row[2].ToString();
SqlSL.Version = row[3].ToString();
list.Add(SqlSL);
}
return list;
}
catch
{
return null;
}
}
}
}
Create new class its name to SqlServerList and write this below code on SqlServerList class.
namespace SqlServer
{
[Serializable]
class SqlServerList : IComparable, ICloneable
{
public SqlServerList()
{
ServerName = string.Empty;
InstanceName = string.Empty;
IsClustered = string .Empty ;
Version = string.Empty;
}
#region ICloneable Members
public object Clone()
{
try
{
if (this == null)
{
return null;
}
SqlServerList SqlSL = new SqlServerList { ServerName = ServerName, InstanceName = InstanceName, IsClustered = IsClustered, Version = Version };
return SqlSL;
}
catch
{
throw new NotImplementedException();
}
}
#endregion
#region IComparable Members
public int CompareTo(object obj)
{
try
{
if (!(obj is SqlServerList))
{
throw new Exception("obj is not an instance of SqlServerList");
}
if (this == null)
{
return -1;
}
return ServerName.CompareTo((obj as SqlServerList).ServerName);
}
catch
{
throw new NotImplementedException();
}
}
#endregion
public string ServerName { get; set; }
public string InstanceName { get; set; }
public string IsClustered { get; set; }
public string Version { get; set; }
}
}
use this class :
- How to Find All SQL Server Instance Running in Local Network c#
- How to find which version of SQL Server is running?
- ping to find hosts in current local network
- Free, simple code to find out what SQL statements are running slow in SQL Server right now
- how-to upgrade all local docker images
- how to execute sql script in c#
- How to read and save Images in a Sql Server Database using ADO.NET and C#
- how to add linked server in SQL server.
- A network-related or instance-specific error occurred while establishing a connection to SQL Server
- How To Use Dynamic Sql in Sql Server ?
- How to setup a test/dev Datazen Server instance in Microsoft Azure
- Find all used ports list in EBS R12 Instance
- SQL Server 2008 - How to convert GMT(UTC) datetime to local datetime?
- SQL server, get all running sessions on the SQL server
- Find All local extrema
- How To: Reset Identity column in SQL Server
- How to search the available space in SQL server.
- How to delete duplicate rows without children in sql server
- tomcat 如何把请求(request)映射到servlet
- 2011年的11个网页设计趋势热点zt
- Websphere 命令行部署与管理应用
- TinyCLR的this赋值语句的缘起和解决
- 用MSSQL计算2的10000次方
- How to Find All SQL Server Instance Running in Local Network c#
- 22个HTML5的初级技巧
- JavaScript浏览器兼容(Firefox 3.x, IE 8)
- Log4j使用总结
- 在Sliverlight中使用动态图片背景(gif),让你的图片动起来
- Win32 API笔记
- sscanf 用法详解
- 用MSSQL计算2的10000次方
- Solaris硬盘分区简介