怎么搜索到局域网内的sqlserver数据库服务器的名字?
问题点数:20、回复次数:11Top
1 楼xhfjy(峰)回复于 2002-01-29 11:52:10 得分 0
用SQL-DMOTop
2 楼playyuer(退休干部 卧鼠藏虫)回复于 2002-01-29 11:52:14 得分 0
ref: SQLDMOTop
3 楼ls176(快按Alt+Tab)回复于 2002-01-29 11:54:57 得分 0
说详细点,能不能给个源码?Top
4 楼HungryBoy(http://www.zhijian.net)回复于 2002-01-29 11:59:34 得分 0
用SQL语句:
select Host_NameTop
5 楼uguess(天地间,有我在行走!)回复于 2002-01-29 12:04:19 得分 0
:
Dim svr As New SQLDMO.SQLServer
Dim db As SQLDMO.Database
Dim i As Integer
svr.Connect "(local)", "sa"
Set db = svr.Databases("pubs")
For i = 1 To db.Tables.Count
Debug.Print db.Tables(i).Name
next
Top
6 楼ls176(快按Alt+Tab)回复于 2002-01-29 15:39:46 得分 0
不解Top
7 楼ls176(快按Alt+Tab)回复于 2002-01-29 16:44:42 得分 0
啊扑Top
8 楼ls176(快按Alt+Tab)回复于 2002-01-30 08:29:58 得分 0
再啊扑Top
9 楼uguess(天地间,有我在行走!)回复于 2002-01-30 09:01:48 得分 0
如果你实在看不懂,我想你最好搜一搜以前的帖子,这是一个经典问题,看看以前的帖子中是否对你有帮助!!
Top
10 楼dingfuhao(丁丁)回复于 2002-01-30 09:51:09 得分 20
用SQLDMO可以,sqlserver2000的盘上有例子
'In form
'Combox --txtserver
'checkbox ---chkAuthentication
'textbox --txtUsername,txtPasswd
'CommandButton --cmdOK,cmdDisconnect,cmdCancel
Private sUsername As String
Private sPasswd As String
'Use the SQL DMO object to find available SQL Servers
Private oSQLServerDMOApp As SQLDMO.Application
'Use the SQLServer object to connect to a specific server
Public WithEvents oSQLServer As SQLDMO.SQLServer
'Determine is NT Authentication is to be used or not
Private Sub chkAuthentication_Click()
If chkAuthentication.Value = vbChecked Then
'This assumes a trusted connection
Frame1.Enabled = False
Label1.Enabled = False
Label2.Enabled = False
Else
'This assumes a login is required
Frame1.Enabled = True
Label1.Enabled = True
Label2.Enabled = True
End If
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdDisconnect_Click()
'When done with the connection to SQLServer you must Disconnect
If Not oSQLServer Is Nothing Then
oSQLServer.DisConnect
Set oSQLServer = Nothing
End If
End Sub
Private Sub cmdOK_Click()
On Error GoTo ErrorHandler
Set oSQLServer = New SQLDMO.SQLServer
oSQLServer.LoginTimeout = -1 '-1 is the ODBC default (60) seconds
'Connect to the Server
If chkAuthentication Then
With oSQLServer
'Use NT Authentication
.LoginSecure = True
'Do not reconnect automatically
.AutoReConnect = False
'Now connect
.Connect txtServer.Text
End With
Else
With oSQLServer
'Use SQL Server Authentication
.LoginSecure = False
'Do not reconnect automatically
.AutoReConnect = False
'Use SQL Security
.Connect txtServer.Text, sUsername, sPasswd
End With
End If
MsgBox "Your Login: " & oSQLServer.Login
'Show next form
'frm.show
'Me.Hide
Exit Sub
ErrorHandler:
MsgBox "Error: " & Err.Number & " " & Err.Description, vbOKOnly, "Login Error"
End Sub
Private Sub Form_Load()
Dim i As Integer
'Use the SQL DMO Application Object to find the available SQL Servers
Set oSQLServerDMOApp = New SQLDMO.Application
Dim namX As NameList
Set namX = oSQLServerDMOApp.ListAvailableSQLServers
For i = 1 To namX.Count
txtServer.AddItem namX.Item(i)
Next
'Show top server
txtServer.ListIndex = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
If Not oSQLServer Is Nothing Then
'When done with the connection to SQLServer you must Disconnect
oSQLServer.DisConnect
End If
Set oSQLServer = Nothing
Set oSQLServerDMOApp = Nothing
End Sub
Private Sub oSQLServer_CommandSent(ByVal SQLCommand As String)
'CommandSent event occurs when SQL-DMO submits a Transact-SQL command batch to the connected instance
Dim sMsg As String
sMsg = "CommandSent: " & vbCrLf & _
SQLCommand
MsgBox sMsg, vbOKOnly, "SQLServer Object Event"
End Sub
Private Function oSQLServer_ConnectionBroken(ByVal Message As String) As Boolean
'ConnectionBroken event occurs when a connected SQLServer object loses its connection
Dim sMsg As String
sMsg = "ConnectionBroken: " & vbCrLf & _
Message
MsgBox sMsg, vbOKOnly, "SQLServer Object Event"
End Function
Private Function oSQLServer_QueryTimeout(ByVal Message As String) As Boolean
'QueryTimeout event occurs when Microsoft?SQL Server?cannot complete execution of a Transact-SQL command batch within a user-defined period of time
Dim sMsg As String
sMsg = "QueryTimeout: " & vbCrLf & _
Message
MsgBox sMsg, vbOKOnly, "SQLServer Object Event"
End Function
Private Sub oSQLServer_RemoteLoginFailed(ByVal Severity As Long, ByVal MessageNumber As Long, ByVal MessageState As Long, ByVal Message As String)
'RemoteLoginFailed event occurs when an instance of Microsoft?SQL Server?attempts to connect to a remote server fails
Dim sMsg As String
sMsg = "RemoteLoginFailed: " & vbCrLf & _
"Severity: " & Severity & vbCrLf & _
"MessageNumber: " & MessageNumber & vbCrLf & _
"MessageState: " & MessageState & vbCrLf & _
"Message: " & Message
MsgBox sMsg, vbOKOnly, "SQLServer Object Event"
End Sub
Private Sub oSQLServer_ServerMessage(ByVal Severity As Long, ByVal MessageNumber As Long, ByVal MessageState As Long, ByVal Message As String)
'ServerMessage event occurs when a Microsoft?SQL Server?success-with-information message is returned to the SQL-DMO application
Dim sMsg As String
sMsg = "ServerMessage: " & vbCrLf & _
"Severity: " & Severity & vbCrLf & _
"MessageNumber: " & MessageNumber & vbCrLf & _
"MessageState: " & MessageState & vbCrLf & _
"Message: " & Message
MsgBox sMsg, vbOKOnly, "SQLServer Object Event"
End Sub
Private Sub txtPasswd_Change()
sPasswd = txtPasswd.Text
End Sub
Private Sub txtUsername_Change()
sUsername = txtUsername.Text
End Sub
Top
11 楼ls176(快按Alt+Tab)回复于 2002-01-30 10:18:45 得分 0
谢谢Top
相关问题
- 如何获取局域网中的SQLSERVER服务器,服务器的数据库列表,数据库中的数据表列表
- 如何远程连接局域网内数据库服务器。
- 如何得到局域网中的所有数据库服务器名称?
- 如何搜索局域网中的可用数据库服务器
- C#写的c/s结构sqlserver数据库程序,发布的局域网其它机器运行时提示提不到Sql服务器,如何解决.
- 100分,如何判断局域网中的主机是不是数据库服务器,是何类型的数据库服务器?回答有分
- 急!更新一个服务器的数据库时更新局域网中另外一个服务器的数据库的数据
- 如果服务器不是本机(程序在一服务器,数据库在一服务器,局域网),如何连接sql ??
- 如何透过代理服务器连接到远程局域网中的一台机器上的数据库
- 如何用asa构建小型局域网数据库服务器?能说一说具体步骤吗?谢谢!




