好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

ASP.NET获取MS SQL Server安装实例实现思路及代码

参考MSDN的文章 http://msdn.microsoft测试数据/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实例。

查看更多关于ASP.NET获取MS SQL Server安装实例实现思路及代码的详细内容...

  阅读:48次