Hi,
What I want to do is simple to explain, hard to obtain (i guess):
I want to fill a dropdownlist with the names of the sqlservers detected on the system. I′ve installed a sw recently that prompts for that, and when you select that server, then it prompts you to insert username and password, and then appears a dropdownlist again with the names of the databases of that sqlserver.
Is this possible to do, at least fill dropdownlists with sqlservers and database names?!?I don't see how, thanks!
Hi dvd,
try this
|||DataTable servers = ((DbDataSourceEnumerator)SqlClientFactory.Instance.CreateDataSourceEnumerator()).GetDataSources();
servers.Columns.Add(newDataColumn("FullServerName",typeof(String),"ServerName + ISNULL(IIF(InstanceName <> \'\', (\'\\\' + InstanceName), InstanceName), \'\') "));
this.ddlServer.ValueMember ="FullServerName";
this.ddlServer.DisplayMember ="FullServerName";
the server table will contains the server and instance installed on each server, after you can bind to whatever you need.
hope this help
kpeguero@.hotmail.com:
Hi dvd,
try this
DataTable servers = ((DbDataSourceEnumerator)SqlClientFactory.Instance.CreateDataSourceEnumerator()).GetDataSources();
servers.Columns.Add(newDataColumn("FullServerName",typeof(String),"ServerName + ISNULL(IIF(InstanceName <> \'\', (\'\\\' + InstanceName), InstanceName), \'\') "));
this.ddlServer.ValueMember ="FullServerName";
this.ddlServer.DisplayMember ="FullServerName";
the server table will contains the server and instance installed on each server, after you can bind to whatever you need.
hope this help
Ok so I've done this:
When you click a button, it fills a dropdownlist with the instances of the sqlservers available:
protected void Button1_Click(object sender, EventArgs e)
{
DbProviderFactory dbpf = SqlClientFactory.Instance;
DbDataSourceEnumerator instancia = dbpf.CreateDataSourceEnumerator();
DataTable dt = instancia.GetDataSources();
if (dt.Rows.Count < 1)
ddlServer.Items.Add("No items");
else{
foreach (DataRow dr in dt.Rows)
{
ddlServer.Items.Add(dr["ServerName"].ToString());
}
}
}
However it gives always the "No items" issue, which means no sql server found...am I missing something?!?Thanks!
|||I dont know how you can get the server name but if you have the server name you can get the rest of the info.
SELECT * from <servername>.master.dbo.sysdatabases.
||| I've been trying hard on this, however, no success. Using the last code I've posted, the only thing I get is "No items". Am I missing something? Cde on my web.config, saying which is my provider, factory or something? Appreciate a little help, thanks a lot!
No one?Really stuck on this!
No comments:
Post a Comment