做一个类似Sql Server里的管理服务器工具,为了得到SQL服务器的列表,代码具体如下:
老是抱错,搞了一天没有搞定,烦!
1SQLDMO.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();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 }
老是抱错,搞了一天没有搞定,烦!