做一个类似Sql Server里的管理服务器工具,为了得到SQL服务器的列表,代码具体如下:
老是抱错,搞了一天没有搞定,烦!
1
SQLDMO.Application sqlApp = new SQLDMO.Application();
2
SQLDMO.NameList ServerName = null;
3
try
4
{
5
ServerName = sqlApp.ListAvailableSQLServers();
6
}
7
catch(System.InvalidCastException err)
8
{
9
MessageBox.Show(err.Message +"\n" + err.StackTrace);
10
return;
11
}
12
this.listView1.Items.Clear();
13
for(int i=0;i<ServerName.Count;i++)
14
{
15
ListViewItem item = new ListViewItem(ServerName.Item(i+1));
16
this.listView1.Items.Add(item);
17
}
ServerName = sqlApp.ListAvailableSQLServers();![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
老是抱错,搞了一天没有搞定,烦!