zoukankan      html  css  js  c++  java
  • C# 启动停止SQLServer数据库服务器

    C#启动停止SQL数据库服务方法之一:

    在命令行里填写命令:net start/stop mssqlserver

    C#启动停止SQL数据库服务方法之二:

    通过C#代码实现;

    class Program : Form
    {
    public Program()
    {
    Button btn1 = new Button();
    btn1.Parent = this;
    btn1.Text = "启动 SQL SERVER";
    btn1.Tag = "START";
    btn1.Top = 50;
    btn1.Left = 20;
    btn1.Width = 120;
    btn1.Click += new EventHandler(Button_Click);

    Label la = new Label();
    la.Text = "C#启动SQL服务";
    la.ForeColor = System.Drawing.Color.Green;
    la.Left = 100;
    la.Top = 20;
    la.Parent = this;

    Button btn2 = new Button();
    btn2.Parent = this;
    btn2.Text = "停止 SQL SERVER";
    btn2.Tag = "STOP";
    btn2.Top = 50;
    btn2.Left = btn1.Right + 10;
    btn2.Width = 120;
    btn2.Click += new EventHandler(Button_Click);

    this.Text = "C#启动SQL服务";
    }

    void Button_Click(object sender, EventArgs e)
    {
    string s = (sender as Button).Tag.ToString();
    ServiceController sc = new ServiceController("MSSQLSERVER");
    if (s == "START" && sc.Status.Equals(ServiceControllerStatus.Stopped))
    {
    sc.Start();
    MessageBox.Show("SQL数据库服务启动成功!", "提示信息");
    }
    if (s == "STOP" && !sc.Status.Equals(ServiceControllerStatus.Stopped))
    {
    sc.Stop();
    MessageBox.Show("SQL数据库服务已经关闭!", "提示信息");
    }
    }

    static void Main(string[] args)
    {
    Application.Run(new Program());
    }
    }

  • 相关阅读:
    SAMBA服务初学练习
    NFS与AutoNFS实例
    NTP服务简介
    DHCP服务简单搭建步骤
    HBase文档操作--练习篇
    Hadoop体系结构管理
    HBase表结构设计--练习篇
    HBase备份恢复练习
    MongoDB管理练习
    24_BlockingQueue接口
  • 原文地址:https://www.cnblogs.com/wlming/p/5113494.html
Copyright © 2011-2022 走看看