473,385 Members | 1,712 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,385 software developers and data experts.

List of Sqlservers on LAN

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
Nov 16 '05 #1
6 2817
Hi reza!

you need to call the NetServerEnum API
http://www.codeproject.com/cs/combob...erdropdown.asp

--
Best Regards
Yanick Lefebvre
Nov 16 '05 #2
Hello,

Easiest thing to do IMHO is to make a ref to the SQLDMO.dll and call the
method that follows :

SQLDMO.Application app = new SQLDMO.ApplicationClass();

SQLDMO.NameList lst = app.ListAvailableSQLServers();

IEnumerator ie = lst.GetEnumerator();

while (ie.MoveNext())

{

Debug.WriteLine(ie.Current.ToString());

}

HTH,

Alex


"Reza Alirezaei" <an*******@discussions.microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #3
that works fine,,,how can I get a list of databases available on the
specified server on a separate Combobox?

"Trebek" <al********@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Hello,

Easiest thing to do IMHO is to make a ref to the SQLDMO.dll and call the
method that follows :

SQLDMO.Application app = new SQLDMO.ApplicationClass();

SQLDMO.NameList lst = app.ListAvailableSQLServers();

IEnumerator ie = lst.GetEnumerator();

while (ie.MoveNext())

{

Debug.WriteLine(ie.Current.ToString());

}

HTH,

Alex


"Reza Alirezaei" <an*******@discussions.microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
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


Nov 16 '05 #4
it returns a collection called a NameList, just use foreach.

private SQLDMO.NameList sqlServers;

sqlDMOApp = new SQLDMO.Application();

sqlServers = sqlDMOApp.ListAvailableSQLServers();

foreach (string server in sqlServers)

{

comboBox1.Items.Add(server);

}

"Reza Alirezaei" <an*******@discussions.microsoft.com> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
that works fine,,,how can I get a list of databases available on the
specified server on a separate Combobox?

"Trebek" <al********@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Hello,

Easiest thing to do IMHO is to make a ref to the SQLDMO.dll and call the
method that follows :

SQLDMO.Application app = new SQLDMO.ApplicationClass();

SQLDMO.NameList lst = app.ListAvailableSQLServers();

IEnumerator ie = lst.GetEnumerator();

while (ie.MoveNext())

{

Debug.WriteLine(ie.Current.ToString());

}

HTH,

Alex


"Reza Alirezaei" <an*******@discussions.microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
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



Nov 16 '05 #5
look up the sp_databases stored procedure..

//**
using System.Data;
using System.Data.SqlClient;

private void ListDatabases(string serverName)
{
SqlConnection cn = new SqlConnection("Integrated Security=SSPI;Persist
Security Info=False;User ID=sa;Initial Catalog=te;Data Source=" + serverName
+ ";");

try
{
cn.Open();
SqlDataReader dr = (new SqlCommand("sp_databases",
cn)).ExecuteReader();
}
catch
{
if (cn.State == ConnectionState.Open) {cn.Close();}
return;
}

Console.WriteLine("List of [" + serverName + "] SQL Server" );
while (dr.Read())
{
Console.WriteLine(dr["DATABASE_NAME"] as string);
}

cn.Close();
}
//***

--
Best Regards
Yanick Lefebvre
"Reza Alirezaei" <an*******@discussions.microsoft.com> a écrit dans le
message de news:eH**************@TK2MSFTNGP09.phx.gbl...
that works fine,,,how can I get a list of databases available on the
specified server on a separate Combobox?

"Trebek" <al********@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Hello,

Easiest thing to do IMHO is to make a ref to the SQLDMO.dll and call the
method that follows :

SQLDMO.Application app = new SQLDMO.ApplicationClass();

SQLDMO.NameList lst = app.ListAvailableSQLServers();

IEnumerator ie = lst.GetEnumerator();

while (ie.MoveNext())

{

Debug.WriteLine(ie.Current.ToString());

}

HTH,

Alex


"Reza Alirezaei" <an*******@discussions.microsoft.com> wrote in message
news:ut**************@TK2MSFTNGP09.phx.gbl...
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



Nov 16 '05 #6
doh, didnt see "databases".

Zoury has it right, also if you want to get more detailed information you
can just hit the sysdatabases table in the master databases, pretty much all
sp_databases is doing.

select * from master.dbo.sysdatabases

Your real problem is that your choice is based off the server selection they
make and the security context your going to connect as. You can either make
them select the server, then enter security info, then pass them as
variables to the sqlconnection string, OR embed trusted or a sql login that
you know has rights to the servers (kinda dangerous).

"Zoury" <ya*************@hotmail.com> wrote in message
news:u#**************@tk2msftngp13.phx.gbl...
look up the sp_databases stored procedure..

//**
using System.Data;
using System.Data.SqlClient;

private void ListDatabases(string serverName)
{
SqlConnection cn = new SqlConnection("Integrated Security=SSPI;Persist
Security Info=False;User ID=sa;Initial Catalog=te;Data Source=" + serverName + ";");

try
{
cn.Open();
SqlDataReader dr = (new SqlCommand("sp_databases",
cn)).ExecuteReader();
}
catch
{
if (cn.State == ConnectionState.Open) {cn.Close();}
return;
}

Console.WriteLine("List of [" + serverName + "] SQL Server" );
while (dr.Read())
{
Console.WriteLine(dr["DATABASE_NAME"] as string);
}

cn.Close();
}
//***

--
Best Regards
Yanick Lefebvre
"Reza Alirezaei" <an*******@discussions.microsoft.com> a écrit dans le
message de news:eH**************@TK2MSFTNGP09.phx.gbl...
that works fine,,,how can I get a list of databases available on the
specified server on a separate Combobox?

"Trebek" <al********@intheformofaquestion.com> wrote in message
news:40***********************@nnrp.fuse.net...
Hello,

Easiest thing to do IMHO is to make a ref to the SQLDMO.dll and call the method that follows :

SQLDMO.Application app = new SQLDMO.ApplicationClass();

SQLDMO.NameList lst = app.ListAvailableSQLServers();

IEnumerator ie = lst.GetEnumerator();

while (ie.MoveNext())

{

Debug.WriteLine(ie.Current.ToString());

}

HTH,

Alex


"Reza Alirezaei" <an*******@discussions.microsoft.com> wrote in message news:ut**************@TK2MSFTNGP09.phx.gbl...
> 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
>
>



Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: massimo | last post by:
Hey, I wrote this program which should take the numbers entered and sort them out. It doesn¹t matter what order, if decreasing or increasing. I guess I'm confused in the sorting part. Anyone...
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...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
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?
5
by: Kurt | last post by:
Hi, is it possible to get SQL Server list in VB.NET whitout SQLDMO, only with ..NET functions? Sergio
5
by: Craig G | last post by:
without using SQLDMO is there another way, i've used the SQLDMO way but have had a few issues with it. is there another way? Cheers, Craig
3
by: Zack Sessions | last post by:
I am using VB.NET 2003. I found the following sample code here in an article: Dim oSQLServerDMOApp As New SQLDMO.Application Dim i As Integer Dim namX As SQLDMO.NameList namX =...
2
by: j-in-uk | last post by:
Can i get a list of sql databases by just connecting to the server programmatically string myConnString = "Integrated Security=SSPI;Initial Catalog={0};Data Source=" + serverName +";";...
2
by: querry | last post by:
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.