在C#中用SQLDMO得到指定SQL服务器所有数据库的列表

        private void getDataBase(string serverName)
        {
            //得到指定SQL服务器(serverName)所有数据库的列表
            SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
            SQLDMO.SQLServer srv = new SQLDMO.SQLServerClass();                
            srv.Connect(serverName,"sa","");
            foreach(SQLDMO.Database db in srv.Databases)
            {
                if(db.Name != null)
                {
                    ListViewItem DBItem = new  ListViewItem();
                    DBItem.SubItems[0].Text = db.Name.ToString();
                    lvwDB.Items.Add(DBItem);
                }
            }
        } 

你可能感兴趣的:(sql,数据库,String,服务器,C#,null)