try
{
// Get a list of SQL servers available on the networks
DataTable dtSQLServers =
SmoApplication.EnumAvailableSqlServers(false);
foreach (DataRow drServer in dtSQLServers.Rows)
{
String ServerName;
ServerName = drServer["Server"].ToString();
if (drServer["Instance"] != null &&
drServer["Instance"].ToString().Length > 0)
ServerName += @"\" +
drServer["Instance"].ToString();
if (cmbServer.Items.IndexOf(ServerName) < 0)
cmbServer.Items.Add(ServerName);
}
// By default select the local server
Server LocalServer = new Server();
String LocalServerName = LocalServer.Name;
if (LocalServer.InstanceName != null &&
LocalServer.InstanceName.Length > 0)
LocalServerName += @"\" + LocalServer.InstanceName;
Int32 ItemIndex =
cmbServer.FindStringExact(LocalServerName);
if (ItemIndex >= 0)
{
this.cmbDatabase.Sorted = true;
cmbServer.SelectedIndex = ItemIndex;
llblConnect.Enabled = true;
}
else
{
this.cmbServer.Text = "<No available SQL Servers>";
llblConnect.Enabled = false;
}
}
catch (SmoException smoException)
{
MessageBox.Show(smoException.Message);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
--
L. A. Jones
Nicholas Paldino said:
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]
- (e-mail address removed)
Dave said:
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.