Connect to database

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

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.
 
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.
 
I can connect to the the server. I have attached the database to my server
using Management Studio. When I try to connect to the database I get error:
"Cannot connect to default database. Login failed . Login failed for user
'myservername/hp_owner' ". However, if it is not attached I will not an error.
--
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.
 
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.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.
 
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.

what *exactly* is the "Instance" column supposed to show? I can enumerate
my 3 SQL Servers and display the column "Name" returned by
EnumAvailableSqlServers but the column "Instance" displays nothing at all
....


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top