Sunday, February 19, 2012

Error while retrieving servers

I've tried to retrieve and fill a combobox with all my servers on my network, and the program tells me he doesn't found any servers, I've got three instances running (SRV-01,SRV-02,SRV-01\SQLEXPRESS), I really don't understand. So I use

SmoApplication.EnumAvailableSqlServers(true)

to test only on my local machine and no server found ?

Here is the code I used :

this.Cursor = Cursors.WaitCursor;

DataTable dtSqlServer = SmoApplication.EnumAvailableSqlServers(true);

foreach (DataRow drServer in dtSqlServer.Rows)

{

string sServer = drServer["Server"].ToString();

if (drServer["Instance"] != null && drServer["Instance"].ToString().Length > 0)

sServer += @."\" + drServer["Instance"].ToString();

if (listDataBases.Items.IndexOf(sServer) < 0)

listDataBases.Items.Add(sServer);

//Make the local server the default

Server local = new Server();

String serverName = local.Name;

if (local.InstanceName != null && local.InstanceName.Length > 0)

serverName += @."\" + local.InstanceName;

Int32 idx = listDataBases.FindStringExact(serverName);

if (idx >= 0)

listDataBases.SelectedIndex = idx;

this.Cursor = Cursors.Default;

}

Is someone can help me thanks, I use Win XP SP2, VS 2005 team suite, SQL Server 2005 std + SP1, SQL Server 2005 express + SP 1

PS : I've tried without EnumAvailableSqlServers using a simple textbox instead, and when I enter the name of my servers it works ?!!!

I've disabled SQL Server Browser now it see my local server but not my network instances and not my SQL Express instance ?|||Hi, I guess you are messing up with instance and server of the resultset of the enumaration of the server.

http://www.sqlserver2005.de/articles/1/

HTH, jens Suessmeyer.

http://www.sqlserver2005.de

No comments:

Post a Comment