如何在局域网里搜索SQL服务器的信息,比如服务器名称
解决方案 »
- 尝试多次也不能获取源码,请教原因
- vb6的picturebox控件picture属性载入一幅图,如何取消呢?
- 关于的coolgrid控件的问题
- treeview 如何接合listview
- 如何获取"本地连接"的名称
- 关于窗口置顶的问题,非常急
- 谁用过傻瓜打表
- 我的迷惑!请大家帮帮我!
- 如何在一个程序中获取另外一个程序的控件的caption??
- 我发大家都是为了那个分才来这儿的,而不是为了解决问题,共同学习这个目的.如果这个问题是300分,我想会有人回复,是0分可能就没有回复.而现在不知是有人回复还是没人回复.
- 有没有api延时函数, 在线等待
- 新手请教一个简单问题!关于connectionstring!
procedure TForm1.FormCreate(Sender: TObject);
var
SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
begin
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
if serverlist.count<1 then
begin //如果服务器不存在,则退出系统
showmessage('服务器不存在,请检测服务器是否已经开机或者服务是否打开了');
application.Terminate;
end
else
begin
for i:=1 to serverlist.count do
listbox1.Items.Add(serverlist.item(i)) ;
// showmessage(serverlist.item(1)+'服务器已经打开,可以正常使用本系统');
// adoconn.close;
// adoconn.ConnectionString:='Provider=SQLOLEDB.1;Persist Security info=False;UserID=sa;InitialCatalog=ideal_db;DataSource='+ServerList.Item(1);
end;
SQLServer:=NULL;
serverList:=NULL;end;
Use SQL DMO!
'Add a Combox(cboServer) on the Form
Private Sub Form_Load() Dim oApplication As New SQLDMO.Application
Dim oServerGroup As SQLDMO.ServerGroup
Dim oRegisteredServer As SQLDMO.RegisteredServer
cboServer.Clear
' Process all the server groups
For Each oServerGroup In oApplication.ServerGroups
' Process each registered server
For Each oRegisteredServer In oServerGroup.RegisteredServers
' Add each name to the combobox
cboServer.AddItem oRegisteredServer.Name
Next
Next
Set oRegisteredServer = Nothing
Set oServerGroup = Nothing
Set oApplication = Nothing
End Sub
'Add the Following Code
cboServer.Listindex=0 '(the Server Exist)2>>
'Add the reference of micorsoft sqldmo object library
'Add a Combox(cboServer) on the FormPrivate Sub Form_Load()
Dim oSQLServerDMOApp As SQLDMO.Application
Set oSQLServerDMOApp = New SQLDMO.Application
Dim i As Integer
Dim namX As NameList
Set namX = oSQLServerDMOApp.ListAvailableSQLServers
For i = 1 To namX.Count
cboServer.AddItem namX.Item(i)
Next
'Show top server
cboServer.ListIndex = 0 Set namX = Nothing
Set oSQLServerDMOApp = Nothing
End Sub
//
http://expert.csdn.net/Expert/topic/1162/1162450.xml?temp=.2607538