获取SQL Server服务器列表的几种方法
2018-05-30 · 百度认证:青岛四海通达电子科技有限公司官方账号
通过不可视对象oleobject建立和SQLDMO连接来取得网络中SQL的服务器列表
具体代码如下(可下载附件):
String ls_name
Int li_i,li_servercount
Long ll_status
/*避免多次点击而生成重复记录*/
lv_1.DeleteColumns()
lv_1.Deleteitems()
/***************************/
lv_1.Addcolumn('服务器名',left!,700)
OLEObject SQLServer,SQLName
SQLServer = Create OLEObject
SQLName = Create OLEObject
ll_status = SQLServer.ConnectToNewObject('SQLDMO.Application')
If ll_status <> 0 Then
MessageBox('失败','连接SQLDMO失败')
DESTROY SQLServer;
Else
SQLName = SQLServer.ListAvailableSQLServers()
li_servercount = SQLName.Count()
For li_i = 1 To li_servercount
ls_name = String(SQLName.Item(li_i))
lv_1.Additem(ls_name,1)
Next
End If
DESTROY SQLServer;
DESTROY SQLName;