本文整理汇总了C#中Job.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Job.Create方法的具体用法?C# Job.Create怎么用?C# Job.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Server server = new Server(".");
// Get instance of SQL Agent SMO object
JobServer jobServer = server.JobServer;
Job job = null;
JobStep step = null;
JobSchedule schedule = null;
// Create a schedule
schedule = new JobSchedule(jobServer, "Schedule_1");
schedule.FrequencyTypes = FrequencyTypes.OneTime;
schedule.ActiveStartDate = DateTime.Today;
schedule.ActiveStartTimeOfDay = new TimeSpan(DateTime.Now.Hour, (DateTime.Now.Minute + 2), 0);
schedule.Create();
// Create Job
job = new Job(jobServer, "Job_1");
job.Create();
job.AddSharedSchedule(schedule.ID);
job.ApplyToTargetServer(server.Name);
// Create JobStep
step = new JobStep(job, "Step_1");
step.Command = "SELECT 1";
step.SubSystem = AgentSubSystem.TransactSql;
step.Create();
}
示例2: UpdateSQLJob
private bool UpdateSQLJob(int nPeriod, bool bEnable, int nFreq, ref string err)
{
ServerConnection conn = null;
try
{
string connstring = System.Configuration.ConfigurationManager.ConnectionStrings["SQLJob"].ConnectionString;
System.Data.SqlClient.SqlConnection sqlconn = new System.Data.SqlClient.SqlConnection(connstring);
conn = new ServerConnection(sqlconn);
Server server = new Server(conn);
// Get instance of SQL Agent SMO object
JobServer jobServer = server.JobServer;
Job job = jobServer.Jobs["EmailDispatch"];
if (job == null)
{
// Create Job
job = new Job(jobServer, "EmailDispatch");
job.Create();
//job.AddSharedSchedule(schedule.ID);
//job.ApplyToTargetServer(server.Name);
}
JobStep step = job.JobSteps["EmailDispatchProcess"];
if (step == null)
{
// Create JobStep
step = new JobStep(job, "EmailDispatchProcess");
step.Command = "EXEC P_EmailDispatchForSchedule";
step.SubSystem = AgentSubSystem.TransactSql;
step.DatabaseName = conn.DatabaseName;
step.Create();
}
JobSchedule schedule = job.JobSchedules["MinuteDispatch"];
if (schedule == null)
{
// Create a schedule
schedule = new JobSchedule(job, "MinuteDispatch");
schedule.ActiveStartDate = DateTime.Today;
schedule.FrequencyTypes = FrequencyTypes.Daily;
schedule.FrequencyInterval = 1;
if (nFreq == 0)
schedule.FrequencySubDayTypes = FrequencySubDayTypes.Hour;
else if(nFreq == 1)
schedule.FrequencySubDayTypes = FrequencySubDayTypes.Minute;
schedule.FrequencySubDayInterval = nPeriod;
//schedule.ActiveStartTimeOfDay = new TimeSpan(DateTime.Now.Hour, (DateTime.Now.Minute + 2), 0);
schedule.Create();
job.AddSharedSchedule(schedule.ID);
job.ApplyToTargetServer("(local)");
}
else
{
if (nFreq == 0)
schedule.FrequencySubDayTypes = FrequencySubDayTypes.Hour;
else if (nFreq == 1)
schedule.FrequencySubDayTypes = FrequencySubDayTypes.Minute;
schedule.FrequencySubDayInterval = nPeriod;
schedule.Alter();
}
job.IsEnabled = bEnable;
job.Alter();
conn.Disconnect();
return true;
}
catch (Exception ex)
{
err = ex.Message;
if(conn != null)
conn.Disconnect();
return false;
}
}
示例3: Create
/// <summary>
/// 创建包含步骤和计划的作业,返回 string jobid, Kill的JOB
/// </summary>
/// <param name="KeyId">对象ID</param>
/// <returns>返回 string</returns>
public string Create(string KeyId, string JobType)
{
try
{
#region 定义变量
//数据库名称
string strDatabaseName = string.Empty;
//作业名称
string strJobName = string.Empty;
//作业ID
string strJobID = string.Empty;
//作业说明
string strDescription = string.Empty;
//开始时间
DateTime dtStartDate = System.DateTime.Now;
//计划频率,Daily:每天、Weekly:每周、Monthly:每月、Run Once:只运行一次
FrequencyTypes FrequencyType = FrequencyTypes.Daily;
//开始运行时间 如:10:30:00
string strRunStartDate = string.Empty;
//结束运行时间,如:11:05:00
string strRunEndDate = string.Empty;
//数据库服务名
string strSQLServer = string.Empty;
//数据库登录用户
string strUser = string.Empty;
//数据库登录密码
string strPassword = string.Empty;
//时
int hours = 0;
//分
int minutes = 0;
//秒
int seconds = 0;
//命令行
string JobCommandString = string.Empty;
vSchedulerEmailBackup vSchedulerEmailBackupObj = null;
#endregion
//返回vSchedulerEmailBackup 对象,根据id查询
vSchedulerEmailBackupObj = this.FindvSchedulerEmailBackupById(KeyId);
if (vSchedulerEmailBackupObj != null)
{
#region 变量赋值
//strDatabaseName = "ServiceDirectDB";
strDatabaseName = this.GetConfig("strDatabaseName");
string[] strJobNames = vSchedulerEmailBackupObj.TaskName.Split('-');
strJobName = strJobNames[0].ToString() + "-Kill";
if (vSchedulerEmailBackupObj.JobID != null)
{
strJobID = vSchedulerEmailBackupObj.JobID.ToString();
}
strDescription = "KillUTP";
dtStartDate = Convert.ToDateTime(vSchedulerEmailBackupObj.RunOnlyEnd);
switch (vSchedulerEmailBackupObj.ScheduleType)
{
case "Daily":
FrequencyType = FrequencyTypes.Daily;
break;
case "Run Once":
FrequencyType = FrequencyTypes.OneTime;
break;
}
DateTime dtRunOnlyStart = Convert.ToDateTime(vSchedulerEmailBackupObj.RunOnlyStart);
DateTime dtRunOnlyEnd = Convert.ToDateTime(vSchedulerEmailBackupObj.RunOnlyEnd);
strRunStartDate = dtRunOnlyStart.ToLongTimeString();
strRunEndDate = dtRunOnlyEnd.ToLongTimeString();
//开始运行时间 时:分:秒:
hours = dtRunOnlyEnd.Hour;
//结束时间减去5分钟之后在运行Kill的JOB
minutes = dtRunOnlyEnd.Minute - 5;
seconds = dtRunOnlyEnd.Second;
//获取自定义config的值
strSQLServer = this.GetConfig("strSQLServer");
strUser = this.GetConfig("strUser");
//.........这里部分代码省略.........