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

📄 frmintegritychecks.cs

📁 < SQL Server2005程序设计>
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.SqlServer.Management.Smo;
using System.Collections.Specialized;

namespace SMODemos
{
	public partial class frmIntegrityChecks : Form
	{
		public frmIntegrityChecks()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
            Server svr = new Server(cboServers.Text.ToString());
            Database db = svr.Databases[cboDatabase.Text.ToString()];

			StringCollection strCol;
			strCol = db.CheckCatalog();//can also do most DBCC commands
			
			for (int intCount = 0; intCount < strCol.Count; intCount++)
			{
				if (strCol[intCount].Length > 0)
					label1.Text+=System.Convert.ToString((strCol[intCount]));
			}
		}

        private void btnSearch_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            //get a DataTable of the servers
            DataTable dtList = SMOUtilities.ListAllKnownInstances();

            foreach (DataRow dr in dtList.Rows)
            {
                String ServerName;
                ServerName = dr["Server"].ToString();

                if (dr["Instance"] != null && dr["Instance"].ToString().Length > 0)
                    ServerName += @"\" + dr["Instance"].ToString();

                if (cboServers.Items.IndexOf(ServerName) < 0)
                    cboServers.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;

            int intCboIndex = cboServers.FindStringExact(LocalServerName);
            if (intCboIndex >= 0)
                cboServers.SelectedIndex = intCboIndex;

            Cursor = Cursors.Default;
        }

        private void btnSSPI_Click(object sender, EventArgs e)
        {
            try
            {
                //use an hourglass
                Cursor = Cursors.WaitCursor;
                //clear out the items, if you don't do this then
                //the combobox will have dupes when you click on
                //the show system database box
                cboDatabase.Items.Clear();

                //this is a reusable function that fills the 
                //combobox with the available databases on a 
                //particular server, passing in the cbo by reg
                //we will reuse this in a later example
                SMOUtilities.FillComboWithDatabases(cboServers.Text.ToString(), true, ref cboDatabase);

            }
            catch (SmoException exSMO)
            {
                MessageBox.Show(exSMO.Message.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                Cursor = Cursors.Default;
            }

        }
        
	}
}

⌨️ 快捷键说明

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