Click to See Complete Forum and Search --> : How to turn start SQL Server Agent from code?


venAdder
November 24th, 2004, 03:19 PM
Hi,

Is is it possible to check if SQL Server Agent is running and if it is not running start it to schedule tasks from MFC app in VC++.net

Any help is highly apprecited!

Thankx

Krzemo
November 25th, 2004, 08:25 AM
U can use SQL-DMO methods .

Best regards,
Krzemo.

Krzemo
November 25th, 2004, 08:34 AM
JobServer Object

The JobServer object exposes attributes associated with SQL Server Agent. SQL Server Agent is responsible for executing scheduled jobs and notifying operators of Microsoft® SQL Server™ 2000 error conditions or other SQL Server execution or job states.

mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmor01.gif mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/Basics/coe.gifProperties (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_ob_j_2b78.htm#)

AutoStart Property (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_p_a_9mnt.htm)Status Property (Services) (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_p_s_769l.htm)MSXServerName Property (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_p_m_5lvd.htm)Type Property (JobServer) (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_p_t_190y.htm)StartupAccount Property (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_p_s_422h.htm)

mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/Basics/coe.gifMethods (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_ob_j_2b78.htm#)

BeginAlter Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_b_96ec.htm)ReAssignJobsByLogin Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_r_3ezo.htm)CancelAlter Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_c_8gis.htm)Refresh Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_r_1z1g.htm)DoAlter Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_d_9hyc.htm)RemoveJobByID Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_r_40is.htm)EnumJobHistory Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_e_2o4k.htm)RemoveJobsByLogin Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_r_2otg.htm)EnumJobs Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_e_557o.htm)RemoveJobsByServer Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_r_2f1g.htm)EnumSubSystems Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_e2_1ixw.htm)Start Method (FullTextService, JobServer) (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_s_6l2c.htm)GetJobByID Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_g_2yp0.htm)StartMonitor Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_s_6exw.htm)MSXDefect Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_m_8pic.htm)Stop Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_s_3vhg.htm)MSXEnlist Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_m_35ic.htm)StopMonitor Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_s_3oh0.htm)PurgeJobHistory Method (mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/dmoref_m_p_7t44.htm)

Remarks



With the JobServer object, you can:

Start or stop SQL Server Agent on a server running SQL Server.
Manage alerts, jobs, and operators.
Enlist the server in a multiserver administration group.


mk:@MSITStore:C:Program%20FilesMicrosoft%20SQL%20Server80ToolsBookssqldmo.chm::/Basics/note.gif Note The JobServer object is compatible with instances of SQL Server 2000 and SQL Server version 7.0. However, the JobServer2 object extends the functionality of the JobServer object for use with features that are new in SQL Server 2000.





(SQL Books Online)

Best regards,
Krzemo.

venAdder
November 25th, 2004, 04:10 PM
thanks a lot for the guidance, I will look into it.
Meanwhile I have tried the approach that SQL ServerAgent is just another service on windows and tried win api functions for the purpose of querying the status of the service and staerting it.

But no success till now because the server is Onn LAN and I can't find a way to make it work.

OpenSCManager accepts the server name if the computer is remote. but it returns RPC server not available.

I will try both approaches and see hat happens.
Thanks again

venAdder
November 25th, 2004, 04:11 PM
Well the Links ove r there don't work!!!!

Krzemo
November 25th, 2004, 10:41 PM
It was just a copy of CHM help (SQL Server Books Online) from local computer.

It was'nt suppose to work.

But I found an article (over Internet) that fully covers UR problem.
http://msdn.microsoft.com/library/default.asp?url=/msdnmag/issues/01/05/sqldmo/toc.asp?frame=true

And that link works :)

Best regards,
Krzemo

venAdder
November 26th, 2004, 01:41 PM
thnks dude am trying to find out what i need to include in c++ in order to make that work