How to determine if the MSSQL of a machine is started

xiaoxiao2021-03-06  45

/ / Judgment if the MSSQL of a machine is started, it is possible to pass the SQL DMO, but there is no way for the client without MSSQL, this is the 1433 port connected to the MSSQL. If the port number is different, it can be passed Port .unit judge_u;

InterfaceUses Sysutils, Classes, IDBaseComponent, IDcomponent, IDtcpConnection, IDICMPCLIENT, IDTCPCLIENT, iDRAWBASE, iDRAWCLIENT

Function Judgeport (AserverName: Pchar; Aport: Integer): boolean; Function Judgeping (ASERVERNAME: PCHAR): Boolean; Implementation

Function JudgEping (ASERVERNAME: PCHAR): Boolean; // This is used to pin computer. Var ICMP: TidicMpClient; begin icmp: = tidicmpclient.create (nil); icmp.receivetimeout: = 1000; ICMP.HOST: = aservername; Try ICMP.PING; Result: = true; Except Result: = false; end; icmp.free; end;

function JudgePort (AServerName: PChar; APort: Integer): Boolean; var IdTCPClient1: TIdTCPClient; begin IdTCPClient1: = TIdTCPClient.Create (nil); IdTCPClient1.Host: = AServerName; IdTCPClient1.Port: = APort; try IdTCPClient1.Connect; Result : = True; idtcpclient1.disconnect; Except results: = false; end; id; id;

END. // There is a known bug. // 1 If multiple instances are installed on a single computer. // 2 If you do not need TCP / IP protocol, use other connection methods, such as a typical named pipe, you cannot judgment.

转载请注明原文地址:https://www.9cbs.com/read-75020.html

New Post(0)