Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sachin.kale
Starting Member
6 Posts |
Posted - 2008-11-17 : 08:36:28
|
Hi, I am developing one web application where I am adding a job to sql server 2005 scheduler programatically. When I run code i m able to add job to schedular but it does not execute on time. If I create the same job manually, job executes on time.
When saw differences between these two jobs I found out that Job created manually has following additional value: When I click on 'Job Referencing a Schedule' i see Reference between Schedule and Job created but but Job created Programatically gives an error as 'Unknown property Id (Microsoft.SqlServer.SmoEnum)'
I have wasted to much of time on this so please help me to resolve this error.
My code is as follows:
Server srv = default(Server); SqlConnectionInfo connInfo = new SqlConnectionInfo("(local)", "sa", "1234"); connInfo.DatabaseName = "uhl_50"; Microsoft.SqlServer.Management.Common.ServerConnection svrConn = new ServerConnection(connInfo); srv = new Server(svrConn); JobServer jbSrv = srv.JobServer; Job jb = new Job(jbSrv, "Test_Job5"); jb.Create(); JobStep jbstp = default(JobStep); jbstp = new JobStep(jb, "Test_Job_Step5"); jbstp.SubSystem = AgentSubSystem.TransactSql ; jbstp.Command = @"insert into uhl_50.dbo.jobtest values ('kal')"; jbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess; jbstp.OnFailAction = StepCompletionAction.QuitWithFailure; //Create the job step on the instance of SQL Agent. jbstp.Create(); //Define a JobSchedule object variable by supplying the parent job and name arguments in the constructor. JobSchedule jbsch = default(JobSchedule); jbsch = new JobSchedule(jb, "Test_Job_Schedule5"); //Set properties to define the schedule frequency, and duration. jbsch.FrequencyTypes = FrequencyTypes.OneTime; TimeSpan ts1 = default(TimeSpan); ts1 = new TimeSpan(18, 18, 0); jbsch.ActiveStartTimeOfDay = ts1; System.DateTime d = default(System.DateTime); d = new System.DateTime(2008, 11, 17); jbsch.ActiveStartDate = d; jbsch.Create(); jbsch.Refresh();
|
|
sachin.kale
Starting Member
6 Posts |
Posted - 2008-12-10 : 07:35:42
|
I got the solution for this. I just added 'jbsch.Alter()' function. This function resets the Jobschedule and Its References. |
 |
|
|
|
|