zoukankan
html css js c++ java
[原]C#开启停止SqlServer服务
using
System.Diagnostics;
using
System.ServiceProcess;
/**/
///
<summary>
///
程序载入时的状态,Author:Kennytian@msn.com
///
</summary>
private
void
LoatStatus()
{
ServiceController sc
=
new
ServiceController(
"
MSSQLSERVER
"
);
string
status
=
sc.Status.ToString();
sc.Close();
label1.Text
=
"
Current status is:
"
+
status;
if
(status.Equals(
"
Running
"
))
StartSql.Text
=
"
Stop
"
;
else
StartSql.Text
=
"
Start
"
;
}
/**/
///
<summary>
///
开启停止SqlServer服务,Author:Kennytian@msn.com
///
</summary>
///
<param name="text">
按钮上的字
</param>
private
void
StartOrStopSqlServerService(
string
text)
{
ServiceController sc
=
new
ServiceController(
"
MSSQLSERVER
"
);
bool
startText
=
text.Equals(
"
Start
"
);
bool
stopText
=
text.Equals(
"
Stop
"
);
bool
Runned
=
sc.Status.ToString().Equals(
"
Running
"
);
if
(stopText
&&
Runned)
{
label1.Text
=
"
Current status is:Stopped
"
;
sc.Stop();
StartSql.Text
=
"
Start
"
;
}
else
if
(startText
&&
!
Runned)
{
label1.Text
=
"
Current status is:Running
"
;
sc.Start();
StartSql.Text
=
"
Stop
"
;
}
else
{
MessageBox.Show(
"
出现异常,请联系开发人员!
"
,
"
警告
"
, MessageBoxButtons.OK);
}
sc.Close();
}
注
:StartSql是一个按钮,添加一个引用ServiceProcess
查看全文
相关阅读:
PHP thinkPHP6.0 部署
ch09 Sql导入语句
自定义map 搜索
MySql 语句
自定义Mappter
三袋米的故事
WPF中实现文件夹对话框(OpenFileDialog in WPF)
web通过Ajax与WCF交互
项目管理之我见-程序员程序开发步骤
存储过程
原文地址:https://www.cnblogs.com/Kennytian/p/1022503.html
最新文章
关于程序多开的尝试。CreateMutex,OpenMuxtex,ReleaseMutex
afxstate
IDL
VB 字符串数组 vc
DOM懒加载 Detour IDE 窗口刷新
DLL和EXE怎样共享全局变量?
VB 中API声明
SQL查询重复数据和清除重复数据
lucene 笔记
SqlServer的汉字转拼音码的函数
热门文章
微软自带的防反编译工具dotfuscator.exe的使用
windows系统事件查询
在HttpModule中使用gzip,deflate协议对aspx页面进行压缩(转)
C++ Primer学习笔记(第1章第8章)
多处理器编程的艺术读书笔记
C++ Primer学习笔记(第15、16章)
C++ Primer学习笔记(第12章第14章)
C++ Primer学习笔记(第17、18章)
Java Concurrency in Practice
C++ Primer学习笔记(第9章第11章)
Copyright © 2011-2022 走看看