ASP.NET获取MS SQL Server安装实例实现思路及代码
更新时间:2013年01月29日 11:11:04 作者:
在演示中,是把找到的实例显示于DropDownList控件中。首先在.aspx拉一个DropDownList控件,感兴趣的朋友可以了解下哦,或许对你有所帮助
参考MSDN的文章 http://msdn.microsoft.com/zh-cn/library/a6t1z9x2.aspx中所指的SqlDataSourceEnumerator类别,是应用程序在当前的网络中查找SQL Server实例。
Insus.NET在演示中,是把找到的实例显示于DropDownList控件中。首先在.aspx拉一个DropDownList控件:
Server: <asp:DropDownList ID="DropDownListInstance" runat="server"></asp:DropDownList>
然后在Page_Load事件写:
View Code
protected void Page_Load(object sender, EventArgs e)
{
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSources();
foreach (DataRow dr in dataTable.Rows)
{
if (string.IsNullOrEmpty(dr["InstanceName"].ToString()))
this.DropDownListInstance.Items.Add(string.Concat(dr["ServerName"]));
else
this.DropDownListInstance.Items.Add(string.Concat(dr["ServerName"], "\\", dr["InstanceName"]));
}
}
运行结果,Insus.NET的手提电脑安装了SQL Server 2012和SQL Server 2008 R2,因此显示两个SQL Server实例。
Insus.NET在演示中,是把找到的实例显示于DropDownList控件中。首先在.aspx拉一个DropDownList控件:
复制代码 代码如下:
Server: <asp:DropDownList ID="DropDownListInstance" runat="server"></asp:DropDownList>
然后在Page_Load事件写:
复制代码 代码如下:
View Code
protected void Page_Load(object sender, EventArgs e)
{
DataTable dataTable = SqlDataSourceEnumerator.Instance.GetDataSources();
foreach (DataRow dr in dataTable.Rows)
{
if (string.IsNullOrEmpty(dr["InstanceName"].ToString()))
this.DropDownListInstance.Items.Add(string.Concat(dr["ServerName"]));
else
this.DropDownListInstance.Items.Add(string.Concat(dr["ServerName"], "\\", dr["InstanceName"]));
}
}
运行结果,Insus.NET的手提电脑安装了SQL Server 2012和SQL Server 2008 R2,因此显示两个SQL Server实例。
您可能感兴趣的文章:
- ASP.NET Core部署前期准备 使用Hyper-V安装Ubuntu Server 16.10
- 在CentOS6.5上使用Jexus安装部署ASP.NET MVC4和WebApi
- asp.net mvc3.0安装失败如何解决
- 64 位 ASP.Net 已注册 需要 32 位 ASP.Net 才能安装 Microsoft Reporting
- Asp.Net Couchbase Memcached图文安装调用开发
- ASP.NET Sql Server安装向导(aspnet_regsql.exe)错误解决一例
- Asp.net与SQLserver一起打包部署安装图文教程
- asp.net Ajax 安装与卸载方法
- Asp.Net Core简介与安装教程
相关文章
System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 登录失败。
今天帮客户配置服务器的时间,安全设置后,将sqlserver以普通用户权限运行的时候提示这个错误。2011-08-08
asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码
本篇文章主要是对asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码进行了介绍,需要的朋友可以过来参考下,需要对大家有所帮助2014-02-02
asp.net System.Guid ToString五种格式
这篇文章主要介绍了asp.net System.Guid ToString五种格式,需要的朋友可以参考下2017-02-02


最新评论