⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smoutilities.cs

📁 < SQL Server2005程序设计>
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Data;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

namespace SMODemos
{
    class SMOUtilities
    {
        public static void FillComboWithDatabases(string strServerName, bool blnIncludeSystemDB, ref ComboBox cbo)
        {
            int intDBCount = 0;
            //  Fill the db combo
            Server svr = new Server(strServerName);
            
            foreach (Database db in svr.Databases)
            {
                //determine if the system database
                //flag is set and include/exclude
                if (blnIncludeSystemDB || !db.IsSystemObject)
                {
                    intDBCount++;
                    cbo.Items.Add(db.Name);
                }
            }
        }

public static DataTable ListAllKnownInstances()
{
    //this method will return a DataTable
    //based on the all of the servers avaiable
    //this method can take some time depending on your network
    //will also connect to SQL Server 2000 machines too
    DataTable dtServers = new DataTable();
    try
    {
        
        // Obtain a list of all SQL Server available
        //this method returns a DataTable
        dtServers = SmoApplication.EnumAvailableSqlServers(false);
    }

    catch (SmoException exSMO)
    {
        MessageBox.Show(exSMO.ToString());

    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }

    return dtServers;
}

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -