ListAvailableSQLServers Method The ListAvailableSQLServers method returns a NameList object that enumerates network-visible instances of Microsoft® SQL Server™ 2000.Applies ToApplication Object Syntax object.ListAvailableSQLServers( ) as NameListParts objectExpression that evaluates to an object in the Applies To listPrototype (C/C++) HRESULT ListAvailableSQLServers( LPSQLDMONAMELIST* ppServerNames);Returns A NameList object that enumerates instances of SQL Server.Res Nondefault instances of SQL Server are displayed in the form of SERVERNAME/INSTANCENAME.The ListAvailableSQLServers method is supported only for servers and workstations running Microsoft Windows NT® 4.0 and Microsoft Windows 2000.Note ListAvailableSQLServers maps to the ODBC SQLBrowseConnect function, which does not support connection pooling. Therefore, an application that enables connection pooling might encounter the error "Microsoft SQL-DMO (0x800A000E) [SQL-DMO]Not enough storage is available to complete this operation." when calling ListAvailableSQLServers.NameList Object The NameList object is a string container object returned by methods that enumerate Microsoft® SQL Server™ components by name.
例子:VERSION 5.00 Begin VB.Form frmLogin Caption = "Login" ClientHeight = 3855 ClientLeft = 60 ClientTop = 345 ClientWidth = 2820 BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty LinkTopic = "Form2" ScaleHeight = 3855 ScaleWidth = 2820 StartUpPosition = 3 'Windows Default Begin VB.ComboBox cboServer Height = 360 Left = 120 TabIndex = 7 Text = "." Top = 600 Width = 2535 End Begin VB.CommandButton cmdOK Caption = "OK" Default = -1 'True Height = 375 Left = 840 TabIndex = 6 Top = 3240 Width = 1095 End Begin VB.CheckBox chkNTAuthentication Caption = "Use NT Authentication" Height = 255 Left = 120 TabIndex = 5 Top = 1080 Value = 1 'Checked Width = 2535 End Begin VB.TextBox txtPassword Height = 375 Left = 120 TabIndex = 4 Top = 2520 Width = 2535 End Begin VB.TextBox txtLogin Height = 375 Left = 120 TabIndex = 2 Text = "sa" Top = 1680 Width = 2535 End Begin VB.Label Label1 Caption = "Password" Height = 255 Index = 2 Left = 120 TabIndex = 3 Top = 2280 Width = 2295 End Begin VB.Label Label1 Caption = "Login" Height = 255 Index = 1 Left = 120 TabIndex = 1 Top = 1440 Width = 2295 End Begin VB.Label Label1 Caption = "SQL Server" Height = 255 Index = 0 Left = 120 TabIndex = 0 Top = 240 Width = 2295 End End Attribute VB_Name = "frmLogin" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub Form_Load() Dim sqlApp As New SQLDMO.Application Dim NameList As SQLDMO.NameList Dim index As Long
Set NameList = sqlApp.ListAvailableSQLServers For index = 1 To NameList.Count cboServer.AddItem NameList.Item(index) Next End Sub Private Sub cmdOK_Click() Dim SQLServer As New SQLDMO.SQLServer
On Error GoTo ErrorHandler
SQLServer.LoginTimeout = 10
If chkNTAuthentication Then ' integrated NT security SQLServer.LoginSecure = True SQLServer.Connect cboServer.Text Else ' SQL Server security SQLServer.Connect cboServer.Text, txtLogin.Text, txtPassword.Text End If
Dim frm As New frmScript Set frm.SQLServer = SQLServer frm.Show Unload Me Exit Sub
ListAvailSQLServers方法
The ListAvailableSQLServers method returns a NameList object that enumerates network-visible instances of Microsoft® SQL Server™ 2000.Applies ToApplication Object
Syntax
object.ListAvailableSQLServers( ) as NameListParts
objectExpression that evaluates to an object in the Applies To listPrototype (C/C++)
HRESULT ListAvailableSQLServers(
LPSQLDMONAMELIST* ppServerNames);Returns
A NameList object that enumerates instances of SQL Server.Res
Nondefault instances of SQL Server are displayed in the form of SERVERNAME/INSTANCENAME.The ListAvailableSQLServers method is supported only for servers and workstations running Microsoft Windows NT® 4.0 and Microsoft Windows 2000.Note ListAvailableSQLServers maps to the ODBC SQLBrowseConnect function, which does not support connection pooling. Therefore, an application that enables connection pooling might encounter the error "Microsoft SQL-DMO (0x800A000E) [SQL-DMO]Not enough storage is available to complete this operation." when calling ListAvailableSQLServers.NameList Object
The NameList object is a string container object returned by methods that enumerate Microsoft® SQL Server™ components by name.
Begin VB.Form frmLogin
Caption = "Login"
ClientHeight = 3855
ClientLeft = 60
ClientTop = 345
ClientWidth = 2820
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form2"
ScaleHeight = 3855
ScaleWidth = 2820
StartUpPosition = 3 'Windows Default
Begin VB.ComboBox cboServer
Height = 360
Left = 120
TabIndex = 7
Text = "."
Top = 600
Width = 2535
End
Begin VB.CommandButton cmdOK
Caption = "OK"
Default = -1 'True
Height = 375
Left = 840
TabIndex = 6
Top = 3240
Width = 1095
End
Begin VB.CheckBox chkNTAuthentication
Caption = "Use NT Authentication"
Height = 255
Left = 120
TabIndex = 5
Top = 1080
Value = 1 'Checked
Width = 2535
End
Begin VB.TextBox txtPassword
Height = 375
Left = 120
TabIndex = 4
Top = 2520
Width = 2535
End
Begin VB.TextBox txtLogin
Height = 375
Left = 120
TabIndex = 2
Text = "sa"
Top = 1680
Width = 2535
End
Begin VB.Label Label1
Caption = "Password"
Height = 255
Index = 2
Left = 120
TabIndex = 3
Top = 2280
Width = 2295
End
Begin VB.Label Label1
Caption = "Login"
Height = 255
Index = 1
Left = 120
TabIndex = 1
Top = 1440
Width = 2295
End
Begin VB.Label Label1
Caption = "SQL Server"
Height = 255
Index = 0
Left = 120
TabIndex = 0
Top = 240
Width = 2295
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit Private Sub Form_Load()
Dim sqlApp As New SQLDMO.Application
Dim NameList As SQLDMO.NameList
Dim index As Long
Set NameList = sqlApp.ListAvailableSQLServers
For index = 1 To NameList.Count
cboServer.AddItem NameList.Item(index)
Next
End Sub Private Sub cmdOK_Click()
Dim SQLServer As New SQLDMO.SQLServer
On Error GoTo ErrorHandler
SQLServer.LoginTimeout = 10
If chkNTAuthentication Then
' integrated NT security
SQLServer.LoginSecure = True
SQLServer.Connect cboServer.Text
Else
' SQL Server security
SQLServer.Connect cboServer.Text, txtLogin.Text, txtPassword.Text
End If
Dim frm As New frmScript
Set frm.SQLServer = SQLServer
frm.Show
Unload Me
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
End Sub