请问,SQL SERVER问题?

我自逍遥01 2002-04-05 11:25:56
如何在COMBO控件中把局域网中的sql服务器都显示出来,
且在选定后可以读出它所有的数据库名?
谢谢!!!!
...全文
82 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyarrant 2002-04-05
  • 打赏
  • 举报
回复
收藏
jamex 2002-04-05
  • 打赏
  • 举报
回复
同意 gump2000(阿甘)
gump2000 2002-04-05
  • 打赏
  • 举报
回复
例子:

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

ErrorHandler:
MsgBox Err.Description, vbCritical

End Sub


gump2000 2002-04-05
  • 打赏
  • 举报
回复
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 NameList

Parts
object

Expression that evaluates to an object in the Applies To list

Prototype (C/C++)
HRESULT ListAvailableSQLServers(
LPSQLDMONAMELIST* ppServerNames);

Returns
A NameList object that enumerates instances of SQL Server.

Remarks
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.



arfayr 2002-04-05
  • 打赏
  • 举报
回复
应该是SQLDMO.Application
ListAvailSQLServers方法
arfayr 2002-04-05
  • 打赏
  • 举报
回复
使用SQLDMO变成可以解决,具体使用那个类和方法,我记不清了
zihualive 2002-04-05
  • 打赏
  • 举报
回复
阿甘真不错
年糕 2002-04-05
  • 打赏
  • 举报
回复
好样的
dwei 2002-04-05
  • 打赏
  • 举报
回复
GOOD!

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧