M
muyirenyan
Unregistered / Unconfirmed
GUEST, unregistred user!
我的电脑已安装了sql2005,在没有局域网的情况下我试了一下方法都没有得到本机的数据库服务器的默认实例请帮忙看一下
第一种方法:据说sqldmo是sql2000的
SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.NameList sqlServers = sqlApp.ListAvailableSQLServers();
for (int i = 0;
i < sqlServers.Count;
i++)
{
object srv = sqlServers.Item(i + 1);
if (srv != null)
{
this.comboBox1.Items.Add(srv);
}
}
if (this.comboBox1.Items.Count > 0)
this.comboBox1.SelectedIndex = 0;
else
this.comboBox1.Text = " <No available SQL Servers>";
第二种方法:
SqlDataSourceEnumerator instance =SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
foreach (System.Data.DataRow var in table.Rows)
{
comboBox1.Items.Add(var["ServerName"]+"//"+var["InstanceName"]);
}
第一种方法:据说sqldmo是sql2000的
SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.NameList sqlServers = sqlApp.ListAvailableSQLServers();
for (int i = 0;
i < sqlServers.Count;
i++)
{
object srv = sqlServers.Item(i + 1);
if (srv != null)
{
this.comboBox1.Items.Add(srv);
}
}
if (this.comboBox1.Items.Count > 0)
this.comboBox1.SelectedIndex = 0;
else
this.comboBox1.Text = " <No available SQL Servers>";
第二种方法:
SqlDataSourceEnumerator instance =SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
foreach (System.Data.DataRow var in table.Rows)
{
comboBox1.Items.Add(var["ServerName"]+"//"+var["InstanceName"]);
}