中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Delphi > 综合文章
判断MS SQL Server是否启动
作者:未知 时间:2005-08-07 20:58 出处:编程爱好者网站 责编:chinaitpower
              摘要:判断MS SQL Server是否启动
//窗体  
object Form1: TForm1  
  Left = 192  
  Top = 107  
  Width = 442  
  Height = 246  
  Caption = 'Form1'  
  Color = clBtnFace  
  Font.Charset = DEFAULT_CHARSET  
  Font.Color = clWindowText  
  Font.Height = -11  
  Font.Name = 'MS Sans Serif'  
  Font.Style = []  
  OldCreateOrder = False  
  PixelsPerInch = 96  
  TextHeight = 13  
  object Label1: TLabel  
    Left = 216  
    Top = 40  
    Width = 32  
    Height = 13  
    Caption = 'Label1'  
  end  
  object Button1: TButton  
    Left = 32  
    Top = 16  
    Width = 75  
    Height = 25  
    Caption = 'Button1'  
    TabOrder = 0  
    OnClick = Button1Click  
  end  
  object Button2: TButton  
    Left = 48  
    Top = 104  
    Width = 75  
    Height = 25  
    Caption = 'Button2'  
    TabOrder = 1  
    OnClick = Button2Click  
  end  
  object cs: TClientSocket  
    Active = False  
    Address = '202.99.0.172'  
    ClientType = ctNonBlocking  
    Port = 1433  
    Left = 32  
    Top = 48  
  end  
  object Timer1: TTimer  
    Interval = 5000  
    OnTimer = Timer1Timer  
    Left = 80  
    Top = 48  
  end  
end  


////////////代码  
unit Unit1;  

interface  

uses  
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  
  StdCtrls, ScktComp, ExtCtrls;  

const  
  SERVICE_STOPPED=1; // Stopped  
  SERVICE_START_PENDING=2; // Starting  
  SERVICE_STOP_PENDING=3; // Stopping  
  SERVICE_RUNNING=4; // Running  
  SERVICE_CONTINUE_PENDING=5; // Restarting after being paused  
  SERVICE_PAUSE_PENDING=6; // Pausing  
  SERVICE_PAUSED=7; //Paused  

type  
  TForm1 = class(TForm)  
    cs: TClientSocket;  
    Button1: TButton;  
    Timer1: TTimer;  
    Label1: TLabel;  
    Button2: TButton;  
    procedure Button1Click(Sender: TObject);  
    procedure Timer1Timer(Sender: TObject);  
    procedure Button2Click(Sender: TObject);  
  private  
    { Private declarations }  
  public  
    { Public declarations }  
  end;  
  function SQLSCMGetLocalServiceStateA(lpszSvc: PChar;dwErr:PDWORD): Integer;cdecl;external 'w95scm.dll';  

var  
  Form1: TForm1;  

implementation  

{$R *.DFM}  

procedure TForm1.Button1Click(Sender: TObject);  
begin  
  cs.Open;  
end;  

procedure TForm1.Timer1Timer(Sender: TObject);  
begin  
  try  
    cs.Active := true;  
  finally  
    if cs.Active then  
      Label1.Caption := 'Runnig'  
    else  
      Label1.Caption := 'Not Runnig';  
  end;  
end;  

procedure TForm1.Button2Click(Sender: TObject);  
var  
  r,e: DWORD;  
begin  
  r := SQLSCMGetLocalServiceStateA('MSSQLServer',@e);  
  case r of  
    SERVICE_STOPPED:  
      ShowMessage('Stoped');  
    SERVICE_START_PENDING:  
      ShowMessage('Starting');  
    SERVICE_STOP_PENDING:  
      ShowMessage('Stopping');  
    SERVICE_RUNNING:  
      ShowMessage('Running');  
    SERVICE_CONTINUE_PENDING:  
      ShowMessage('Restarting');  
    SERVICE_PAUSE_PENDING:  
      ShowMessage('Pausing');  
    SERVICE_PAUSED:  
      ShowMessage('Paused');  
  end;  
end;  

end.

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有