473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

List of all available sql servers...

45
Hi all,

I am trying to get a list of all the available sql servers and then populate them in a combo box. I do this with the following code taken from http://www.csharphelp.com/archives2/archive342.html

SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.NameList sqlServers = sqlApp.ListAvailableSQLServers();

for (int i = 0; i < sqlServers.Count; i++)
{
object srv = sqlServers.Item(i + 1);
if (srv != null)
{
this.cmbServers.Items.Add(srv);
}
}

if (this.cmbServers.Items.Count > 0)
{
this.cmbServers.SelectedIndex = 0;
}
else
{
this.cmbServers.Text = "<No available SQL Servers>";
}

However, I have a little problem. The above code retrieves a list of all the available servers, but for the local server it returns "(local)".
So, I get the Item (local) instead of the servername of my local server in the Combo Box. I need to get the servername entry in stead of "(local)"

How do I get that??

Many thanks.
May 8 '07 #1
2 2710
cyberdwarf
218 Expert 100+
Hi

We have a routine which looks like this:-
Expand|Select|Wrap|Line Numbers
  1. Private Sub GetDbsNames()
  2. On Error GoTo ErrorConnection
  3. Dim Rs As New ADODB.Recordset
  4. Dim Cnn As New ADODB.Connection
  5.  
  6.     With Cnn
  7.         .Provider = "SQLOLEDB"
  8.         .Properties![Data Source] = ServerName
  9.         .Properties![User Id] = UserName
  10.         .Properties![Password] = Nz(Password, "")
  11.         .Properties![Initial Catalog] = "Master"
  12.         .Open
  13.     End With
  14.     Rs.Open "select name from master.dbo.sysdatabases", Cnn
  15.     Rs.MoveFirst
  16.     Do Until Rs.EOF
  17.     If Rs!name = "Test" Then
  18.         Database.AddItem Rs!name, 0
  19.     Else
  20.         Database.AddItem Rs!name
  21.     End If
  22.     Rs.MoveNext
  23.     Loop
  24.     Rs.Close
  25.     Cnn.Close
  26.     Set Rs = Nothing
  27.     Set Cnn = Nothing
  28.     Exit Sub
  29.  
  30. ErrorConnection:
  31.     Set Cnn = Nothing
  32.  
  33. End Sub
HTH
Steve
May 8 '07 #2
querry
45
Thanks Steve,

Although it is a good solution, but I am looking to populate all the sql servers before I connect to any of them.
May 10 '07 #3

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

Similar topics

5
by: Oliver Braun | last post by:
I know this is a very common issue and I found a lot of hints on this topic in www but I did not find a very good solution for this task. Most of the solutions use SQLDMO to list all sql servers...
1
by: M | last post by:
In .NET (pref. c#) how does one get a list of all available SQL Servers, databases and tables. I need to allow the connection to a database, etc, on the fly. kind of like what happens in SQL Query...
6
by: Reza Alirezaei | last post by:
How can I have a list of all sql servers avaiable on our LAN populated in a DropDownList exacly like what we have when we want to specify Datasource in ADO.Net or wherever? Thanks
1
by: Piotrek Stachowicz | last post by:
Hi, I'd like to display list of all MS SQL servers which are available on the network (I write application which uses database located on one of the machines in my LAN). Has anyone got any idea...
7
by: EvanK | last post by:
Is there a way to access a list of available sql servers in vb and make a dropdown list?
1
by: Roger | last post by:
I would like to get a list of machines on my network (Workstations and/or Servers). Is there a way to do this in VB.Net? Thanks, Rog
0
by: Mike Cox | last post by:
Andy M wrote: > ALERT > > There is a person by the name of Mike Cox who's trying > to turn this mailing list into a Big-8 newsgroup. No, I'm trying to get teh postgresql groups which are...
7
by: Radamand | last post by:
This has been driving me buggy for 2 days, i need to be able to iterate a list of items until none are left, without regard to which items are removed. I'll put the relevant portions of code below,...
6
by: doofy | last post by:
Anyone know how I can pull in a list of available database servers on my computer (which I will then use to populate a combo box)? Even just the namespace to use would be a start, though more...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.