希望在明天

如果,你没有耐心等待成功的到来,那么,你将用一生的耐心去面对失败。

获得局域网中的所有SQL数据库实例


这要使用SQLDMO Com组件

添加引用:


获取局域网中的数据库实例:
            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.comboxServer.Items.Add(srv);
                }

            }


读取指定实例的数据库:
            SQLDMO.SQLServer srv = new SQLDMO.SQLServerClass();
            
try
            
{
                srv.Connect(
this.comboxServer.SelectedItem.ToString(), this.txtUser.Text, this.txtPassword.Text);
            }

            
catch(Exception ex)
            
{
                MessageBox.Show(ex.Message);
                
return;
            }

            
foreach (SQLDMO.Database db in srv.Databases)
            
{
                
if (db.Name != null)
                    
this.comboxDatabase.Items.Add(db.Name);
            }

posted on 2007-06-03 14:05  蒜头  阅读(928)  评论(0编辑  收藏  举报

导航