日期:2014-05-18  浏览次数:20512 次

用程序如何检测SQL SERVER AGENT 是否启动?
用程序如何检测SQL   SERVER   AGENT   是否启动?

用VB或者C都可以,谢谢

------解决方案--------------------
--用SQL语句启动SQL Server Agent服务

exec master..xp_cmdshell 'net start SQLServerAgent '

--参考代码:

--以下是检测MSSQLSERVER服务是否启动,如果要检测代理服务,将MSSQLSERVER改为SQLSERVERAGENT

BOOL CheckSqlService(SC_HANDLE schSCManager)
{
SC_HANDLE schService;
SERVICE_STATUS ssStatus;

schService = OpenService(
schSCManager, // SCM database
"MSSQLSERVER ", // service name
SERVICE_ALL_ACCESS);

if (schService == NULL)
{
return FALSE;
}

// Check the status until the service is no longer start pending.

if (!QueryServiceStatus(
schService, // handle to service
&ssStatus) ) // address of status information structure
{
return FALSE;
}

// Save the tick count and initial checkpoint.

if(ssStatus.dwCurrentState == SERVICE_RUNNING)
{
return TRUE;
}

return FALSE;
}

--------------------

--本机检测可以用楼上的服务方法,远程检测可以访问1433端口。


------解决方案--------------------
在sql server2000服务器上执行,
exec master..xp_cmdshell 'net start '
然后,从返回的结果上查询有没有 SQLSERVERAGENT 该字符窜,有的话就说明已经启动了该服务,如果没有找到,就说明没有启动。
执行后返回的结果如下:
------------------------------------
已经启动以下 Windows 2000 服务:
NULL
Alerter
ASP.NET State Service
Automatic Updates
Background Intelligent Transfer Service
COM+ Event System
Computer Browser
DHCP Client
DHCP Server
Distributed File System
Distributed Link Tracking Client
Distributed Transaction Coordinator
DNS Client
DNS Server
Event Log
FTP Publishing Service
IIS Admin Service
Infrared Monitor
Internet Authentication Service
License Logging Service
Logical Disk Manager
Messenger
Microsoft Search
MSSQLSERVER
Network Connections
NT LM Security Support Provider
Plug and Play
Print Spooler
Protected Storage
Remote Access Connection Manager
Remote Procedure Call (RPC)
Remote Registry Service
Removable Storage
RunAs Service
Security Accounts Manager
Server
Simple Mail Transport Protocol (SMTP)
Simple TCP/IP Services
SQLSERVERAGENT
Symantec AntiVirus
Symantec AntiVirus Definition Watcher
Symantec Event Manager
Symantec Settings Manager
System Event Notification
Task Scheduler
TCP/IP NetBIOS Helper Service
Telephony
Terminal Services
Windows Internet Name Service (WINS)
Windows Management Instrumentation
Windows Management Instrumentation Driver Extensions
Workstation
World Wide Web Publishing Service
NULL
命令成功完成。
NULL
NULL