We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ListAvailableSQLServers

'_______________________________________ Dim i As Integer Dim oSQLApp As New SQLDMO.Application() Dim oNames As SQLDMO.NameList oNames = oSQLApp.ListAvailableSQLServers Try oNames = oSQLApp.ListAvailableSQLServers Catch MsgBox(Err.Description) Exit Sub End Try CmbServer.Items.Clear() For i = 1 To oNames.Count CmbServer.Items.Add(oNames.Item(i)) Next i '_________________________________________ this not working. It gives an error saying 'InvaidCastException'. Kindly help.

2 Replies

AL andy lennard March 27, 2003 09:24 PM UTC

Try this it worked on my XP System under SQL 2000 personal server connected to win 2k server with sql 2000. Dim oSQLDMOApplication, oServersNameList oSQLDMOApplication = CreateObject("SQLDMO.Application") oServersNameList = oSQLDMOApplication.ListAvailableSQLServers() Dim i For i = 1 To oServersNameList.Count MyServerNames.Items.Add(oServersNameList.Item(i)) Next i oSQLDMOApplication = Nothing The difference between this and your code being the use of create object. When I used NEW I got the same result as you. Hope this helps Andrew. > '_______________________________________ > Dim i As Integer > Dim oSQLApp As New SQLDMO.Application() > Dim oNames As SQLDMO.NameList > oNames = oSQLApp.ListAvailableSQLServers > Try > oNames = oSQLApp.ListAvailableSQLServers > Catch > MsgBox(Err.Description) > Exit Sub > End Try > CmbServer.Items.Clear() > For i = 1 To oNames.Count > CmbServer.Items.Add(oNames.Item(i)) > Next i > '_________________________________________ > this not working. It gives an error saying 'InvaidCastException'. > Kindly help. >


JC John Cosmas December 10, 2003 02:09 AM UTC

I had a problem using the oSQLDMOApplication.ListAvailableSQLServers method. My XP box returned a "Object required" message. Please help; I need to somehow enumerate my SQL Servers. The registry method is not very practical because there may be servers not listed in my local registry. > Try this it worked on my XP System under SQL 2000 personal server connected to win 2k server with sql 2000. > > Dim oSQLDMOApplication, oServersNameList > oSQLDMOApplication = CreateObject("SQLDMO.Application") > oServersNameList = oSQLDMOApplication.ListAvailableSQLServers() > Dim i > For i = 1 To oServersNameList.Count > MyServerNames.Items.Add(oServersNameList.Item(i)) > Next i > > oSQLDMOApplication = Nothing > > The difference between this and your code being the use of create object. When I used NEW I got the same result as you. Hope this helps > Andrew. > > > '_______________________________________ > > Dim i As Integer > > Dim oSQLApp As New SQLDMO.Application() > > Dim oNames As SQLDMO.NameList > > oNames = oSQLApp.ListAvailableSQLServers > > Try > > oNames = oSQLApp.ListAvailableSQLServers > > Catch > > MsgBox(Err.Description) > > Exit Sub > > End Try > > CmbServer.Items.Clear() > > For i = 1 To oNames.Count > > CmbServer.Items.Add(oNames.Item(i)) > > Next i > > '_________________________________________ > > this not working. It gives an error saying 'InvaidCastException'. > > Kindly help. > > >

Loader.
Live Chat Icon For mobile
Up arrow icon