use odp.net to create an dbms_scheduler job in csharp

Here is an example of how to create a DBMS_SCHEDULER job in C# using Oracle's ODP.NET library:

main.cs
using Oracle.ManagedDataAccess.Client;

// Set up connection to Oracle database
string connectionString = "DATA SOURCE=<your data source>;PASSWORD=<your password>;USER ID=<your user id>";
OracleConnection connection = new OracleConnection(connectionString);

// Define job name and program name
string jobName = "my_job";
string programName = "my_program";

// Create command to create program
// Replace <program and executable path> with the path to your program and executable
string programCommand = "BEGIN DBMS_SCHEDULER.CREATE_PROGRAM(" +
                         "program_name => :programName," +
                         "program_type => 'EXECUTABLE'," +
                         "program_action => '/<program and executable path>'," +
                         "enabled => FALSE," +
                         "comments => 'My program description.'); END;";
OracleCommand programCommandObj = new OracleCommand(programCommand, connection);
programCommandObj.Parameters.Add(":programName", programName);

// Create command to create job
string jobCommand = "BEGIN DBMS_SCHEDULER.CREATE_JOB(" +
                     "job_name => :jobName," +
                     "job_type => 'EXECUTABLE'," +
                     "job_action => '/<program and executable path>'," +
                     "start_date => SYSTIMESTAMP," +
                     "enabled => FALSE," + 
                     "comments => 'My job description.'," +
                     "program_name => :programName); END;";
OracleCommand jobCommandObj = new OracleCommand(jobCommand, connection);
jobCommandObj.Parameters.Add(":jobName", jobName);
jobCommandObj.Parameters.Add(":programName", programName);

// Open connection and execute commands
connection.Open();
programCommandObj.ExecuteNonQuery();
jobCommandObj.ExecuteNonQuery();
connection.Close();
1819 chars
40 lines

This will create a job named "my_job" that runs an executable program named "my_program". The job will be disabled by default, so you will need to enable it before it can run. You can also specify additional parameters for your job, such as a schedule, using the CREATE_JOB command.

gistlibby LogSnag