Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone
I'm trying to get all sql server instances and i used these three methods
VB
Private Sub method1()
   Dim mc As New Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer
   mc.ConnectionSettings.ProviderArchitecture = ProviderArchitecture.Use64bit
   For Each si As ServerInstance In mc.ServerInstances
      cmbInstances.Items.Add(mc.Name & "\" & si.Name)
   Next
End Sub
Private Sub method2()
   Dim dt As DataTable
   dt = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources
   For Each a As DataRow In dt.Rows
      cmbInstances.Items.Add(a.Item("servername") & "\" & a.Item("instancename"))
   Next
End Sub
Private Sub method3()
   Dim datatable As New DataTable
   datatable = SmoApplication.EnumAvailableSqlServers(false)
   cmbInstances.DisplayMember = "Name"
   cmbInstances.DataSource = datatable
End Sub

But none of these methods seems to be reliable comparing to a "udl" file i create in my windows 7
the udl file always get me a better results than all the above three methods combined .
Any idea?
Kind regards
Posted
Updated 18-Oct-15 21:46pm
v3
Comments
sreeyush sudhakaran 19-Oct-15 3:49am    
You want Details of SQL Server instance or Want to trace how many instances running in current PC?
M. Rawan 19-Oct-15 4:40am    
I want to get all instances in (current PC and current network)
Maciej Los 19-Oct-15 6:42am    
"Any idea?" of what?
M. Rawan 19-Oct-15 7:04am    
Any idea of why a regular "UDL" file gets all sql server instances better than all three above methodes combined
Maciej Los 19-Oct-15 7:13am    
In what manner "'UDL' file gets all sql server instances better than ..." mentioned methods? Are you sure you can prove this statement?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900