Why does the following code do not show any servers? Previously it behaved
erratic, that is, sometimes you servers sometimes you don't. Now I am getting
no servers. I know that there are some issues with SMO. But what I don't
understand is why I have a complete blackout of available servers.
try
{
// Get a list of SQL servers available on the networks
DataTable dtSQLServers =
SmoApplication. EnumAvailableSq lServers(false) ;
foreach (DataRow drServer in dtSQLServers.Ro ws)
{
String ServerName;
ServerName = drServer["Server"].ToString();
if (drServer["Instance"] != null &&
drServer["Instance"].ToString().Len gth 0)
ServerName += @"\" + drServer["Instance"].ToString();
if (cmbServer.Item s.IndexOf(Serve rName) < 0)
cmbServer.Items .Add(ServerName );
}
// By default select the local server
Server LocalServer = new Server();
String LocalServerName = LocalServer.Nam e;
if (LocalServer.In stanceName != null &&
LocalServer.Ins tanceName.Lengt h 0)
LocalServerName += @"\" + LocalServer.Ins tanceName;
Int32 ItemIndex = cmbServer.FindS tringExact(Loca lServerName);
if (ItemIndex >= 0)
{
this.cmbDatabas e.Sorted = true;
cmbServer.Selec tedIndex = ItemIndex;
llblConnect.Ena bled = true;
}
else
{
this.cmbServer. Text = "<No available SQL Servers>";
llblConnect.Ena bled = false;
}
}
catch (SmoException smoException)
{
MessageBox.Show (smoException.M essage);
}
catch (Exception exception)
{
MessageBox.Show (exception.Mess age);
}
--
L. A. Jones
"Nicholas Paldino [.NET/C# MVP]" wrote:
Dave,
If you type the name of the server, does the connection dialog exist?
You say you see them in management studio, but if I recall correctly,
the drop down on the connection dialog for management studio is a MRU (most
recently used) list, not the list of available machines. You have to select
the last item ("browse") to get a list of available servers.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Dave" <Da**@discussio ns.microsoft.co mwrote in message
news:B0******** *************** ***********@mic rosoft.com...
This is kind of a cross forum problem. I am trying to Connect to database
by
clicking on: Tools Connect To Database Select: Microsoft SQL Server
(SqlClient). However, there are no server listed when I click on Refresh.
I
know that 2 instances exist. I see them Management Studio. I think this is
preventing the listing of local instances using SMO.
--
L. A. Jones