Microsoft KB Archive/316799

= HOW TO: Schedule a Package with Visual C++ in SQL Server 2000 =

Article ID: 316799

Article Last Modified on 12/26/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 2000 64-bit Edition
 * Microsoft Visual C++ 6.1

-



This article was previously published under Q316799



IN THIS TASK
SUMMARY
 * Code Sample

REFERENCES



SUMMARY
This article demonstrates how to schedule a Data Transformation Services (DTS) package through Microsoft Visual C++, which may be useful if you must schedule a DTS package programmatically. The example creates a job that runs from January 08, 2002 to January 10, 2002 between 12:30 PM and 14:30 PM, once a day.

back to the top

Code Sample
This article assumes that a DTS package already exists. If you do not have a DTS package, please create one through SQL Server Enterprise Manager, Microsoft Visual Basic, or Microsoft Visual C++. This is a sample program and you must modify the code if you want to use it in your work environment.

// Provide the correct path for Sqldmo.dll.
 * 1) include 
 * 2) undef EOF
 * 1) import &quot;D:\program files\Microsoft SQL Server\80\Tools\Binn\sqldmo.dll&quot; no_namespace

int main(int argc, char* argv[]) {  CoInitialize(NULL);

try {

// Create the SQL Server Object _SQLServerPtr mySQLServer(__uuidof(SQLServer)); // Replace the , , and with yours. mySQLServer->Connect(&quot;&quot;,&quot;&quot;,&quot; &quot;); // Create the Jobs Object JobsPtr myJobs;

// Create the Job Object _JobPtr myJob(__uuidof(Job)); // This name will show up under Jobs in Enterprise Manager. myJob->Name = &quot;myTestJob&quot;;

// Create the JobStep _JobStepPtr myJobStep(__uuidof(JobStep)); myJobStep->Name = &quot;Job Step 1&quot;; myJobStep->StepID = 1;

// Execute a package with a trusted connection. // Replace the  and  with yours. // Check which options are correct for dtsrun. myJobStep->Command = &quot;DTSRun /S  /E /N &quot;;

// Create the JobSchedule Object _JobSchedulePtr myJobSchedule(__uuidof(JobSchedule)); myJobSchedule->Name = &quot;myTestPackage&quot;;

// Job occurs every day myJobSchedule->Schedule->FrequencyType = SQLDMOFreq_Daily;

// Job occurs one time every day myJobSchedule->Schedule->FrequencyInterval = 1;

myJobSchedule->Schedule->ActiveStartDate = 20020108; myJobSchedule->Schedule->ActiveEndDate = 20020110;

myJobSchedule->Schedule->ActiveStartTimeOfDay = 123000; myJobSchedule->Schedule->ActiveEndTimeOfDay = 143000; // Add the Job Object to the JobServer mySQLServer->JobServer->Jobs->Add(myJob); // Start the changes to the job schedule myJob->BeginAlter ; // Add the JobSchedule to the Job myJob->JobSchedules->Add(myJobSchedule);

// Add the Job Step to the Job myJob->AddStepToJob(myJobStep); myJob->StartStepID = 1;

// Apply changes to the Job Schedule myJob->DoAlter ;

}  catch (_com_error& e)   { cout << &quot;Source    : &quot; << e.Source << endl; cout << &quot;Error     : &quot; << e.Error << &quot; &quot; << endl; cout << &quot;Description: &quot; << e.Description << endl ; }

return 0; } back to the top

