本文整理汇总了C#中Job.ApplyToTargetServer方法的典型用法代码示例。如果您正苦于以下问题:C# Job.ApplyToTargetServer方法的具体用法?C# Job.ApplyToTargetServer怎么用?C# Job.ApplyToTargetServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Job
的用法示例。
在下文中一共展示了Job.ApplyToTargetServer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Create
//.........这里部分代码省略.........
myServer = new Server(conn);
string KillID = string.Empty;
//调用删除job方法,传入job名称
//DeleteJob(KillID);
DeleteJob(strJobID);
Job jb = new Job(myServer.JobServer, strJobName);
jb.Description = strDescription;
//更改JOB状态
if (JobType == "enable")
{
jb.IsEnabled = true;
}
switch (JobType)
{
case "enable":
jb.IsEnabled = true;
break;
case "disable":
jb.IsEnabled = false;
break;
case "Insert":
jb.IsEnabled = true;
break;
}
//创建JOB
jb.Create();
#endregion 创建作业
#region 作业步骤
Steps steps = new Steps();
//创建步骤
steps.CreateStepKill(jb, strDatabaseName, KeyId);
#endregion 作业步骤
#region 作业计划属性
JobSchedule jbsch = new JobSchedule(jb, "ScheduleKill");
//计划频率,每几天一次
jbsch.FrequencyTypes = FrequencyType;
if (vSchedulerEmailBackupObj.ScheduleType.Equals("Daily"))
{
//执行间隔 (天)
jbsch.FrequencyInterval = 1;
//当天只执行一次
jbsch.FrequencySubDayTypes = FrequencySubDayTypes.Once;
}
if (strRunStartDate != string.Empty)
{
//开始执行时间
jbsch.ActiveStartTimeOfDay = new TimeSpan(hours, minutes, seconds);
}
//持续时间
if (dtStartDate != null)
{
//开始时间
jbsch.ActiveStartDate = dtStartDate;
}
else
{
jbsch.ActiveStartDate = DateTime.Now;
}
//创建SQL代理实例的作业调度
jbsch.Create();
jb.ApplyToTargetServer(myServer.JobServer.Name);
//创建成功后立刻执行一次开始
//jb.Start();
//创建成功后立刻执行一次结束
#endregion 作业计划属性
string KillJobID = jb.JobID.ToString();
string BillinJobID = string.Empty;
BillinJobID = this.CreateBilling(KeyId, JobType, KillJobID);
//返回作业GUID
return BillinJobID;
}
else
{
return "";
}
}
catch (Exception)
{
return "";
}
}