zoukankan      html  css  js  c++  java
  • How to Find All SQL Server Instance Running in Local Network c#

    代码
    How to Find All SQL Server Instance Running in Local Network c#
    C#
    //Create new class its name to GetInstance and write this below code on GetInstance class.
    using System.Data.Sql;
    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.


    using System;

    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 :

    System.Collections.ArrayList AllInstanceSqlserver
    = SqlServer.GetInstance.GetInstanceName();
  • 相关阅读:
    Hash工具下载地址
    微信聊天记录查看器(程序+源码)
    XEN的启动信息输出到“Platform timer is 14.318MHz HPET”就暂停接收的解决办法
    利用 Serial Over Lan(SOL)搭建 XEN 的调试信息输出环境
    Windows内核开发中如何区分文件对象究竟是文件还是文件夹?
    白盒密码入门
    选择Asp for javascript,非.net。
    8个你至少应该参加一次的极客盛会
    程序员的四种类型
    超棒的30款JS类库和工具
  • 原文地址:https://www.cnblogs.com/JoshuaDreaming/p/1888268.html
Copyright © 2011-2022 走看看