By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,184 Members | 1,558 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,184 IT Pros & Developers. It's quick & easy.

find all datas on a sql server

P: 12

I developed the code below to find all sql server on the network. Once the sql servers have been found display all the database that they have. The first part work. But the I can't get the servers to display their database. I have 3 sql servers, and they all display the databases on the local host, no matter which one I select.

Can anyone check my code below, thanks very much.

How can I put a test connected to database, so i know i have a connection established.

Many thanks in advance,

Expand|Select|Wrap|Line Numbers
  1. Private Sub ServerSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         Dim oSQLServer As New SQLDMO.SQLServer()
  3.         Dim oServerList As SQLDMO.NameList
  4.         Dim databases As SQLDMO.Databases
  5.         Dim i As Integer
  7.         'Finds a list off all the available servers on the network
  8.         oServerList = oSQLServer.Application.ListAvailableSQLServers()
  10.         'Populate the listbox with all the available servers
  11.         Try
  12.             For i = 1 To oServerList.Count
  13.                 lstServers.Items.Add(oServerList.Item(i)).ToString()
  14.             Next
  15.         Catch ex As Exception
  16.             MessageBox.Show(ex.Message)
  17.         End Try
  19.         'Connect by using trusted connection - windows authentication
  20.         If (rdoTrustedConnection.Checked = True) Then
  21.             oSQLServer.LoginSecure = True
  22.             oSQLServer.Connect(lstServers.SelectedValue)
  23.         ElseIf (rdoSQL.Checked = True) Then
  24.             oSQLServer.Connect(lstServers.SelectedValue, txtUsername.Text, txtPassword.Text)
  25.         End If
  27.         'Get all the databases on this server and populate the list box
  28.         databases = oSQLServer.Databases
  30.         Try
  31.             For i = 1 To databases.Count
  32.                 cboDatabases.Items.Add(databases.Item(i).Name)
  33.             Next i
  34.         Catch ex As Exception
  35.             MessageBox.Show(ex.Message)
  36.         End Try
  38.     End Sub 

Oct 11 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.