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
>
>