List of SQL Servers

prem_rajani

Member
Joined
Jul 19, 2005
Messages
22
Location
Coimbatore
Programming Experience
3-5
Hi guyz,

The steps I followed was :

1) In command prompt I executed the line -
tlbImp E:\sqldmo.dll /out:vbSqlDMO which creates an instance for SQLDMO.

2) Then I add this dll as a reference in my project.

3) In form load I populate a combobox filling it up with server name.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i
Dim mySqlDMO As New vbSqlDMO.ApplicationClass
Dim mynamelist As vbSqlDMO.NameList
mynamelist = mySqlDMO.Application.ListAvailableSQLServers
For i = 0 To mynamelist.Count
Dim str As String = mynamelist.Item(i)
ComboBox1.Items.Add(str)
Next
End Sub

I get some typecast error. After inserting a breakpoint it gets stuck in
mynamelist = mySqlDMO.Application.ListAvailableSQLServers

What mistake am I doing or should it be other way of coding. Anyone can please help me.
 
Is this your need?

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Text
Imports System.Data.OleDb
Imports SQLDMO

Function 1:

Public Function ListofServers() As Boolean
Dim dmo As New SQLDMO.Application
Dim lst As NameList
lst = dmo.ListAvailableSQLServers()
If lst.Count = 0 Then
AvailableServers = ""
ListofServers = False
Else
Dim i As Integer, st As String
For i = 1 To lst.Count
st = st & lst.Item(i).ToString & ";"
Next
AvailableServers = st
ListofServers = True
End If
End Function

This function returns True if I take a list of servers in the system successfully, and it also return a string that contain a list of servers found separated by simicolon.

I wonder if that above help you any ?

 
Back
Top