How to run Ms Sql Job using Uipath

Hi,

In SQL database, I have job created to take database backup. How do i run that job using UiPath. Is there any activity available for it?

Please help…Thank you

1 Like

Hi
Welcome back to uipath community

we can do this with the help of UiPath.Database.Activities and with Execute Non Query activity
UiPath.Database.Activities

Cheers @SagarSB

1 Like

Hi
Thanks for quick response…

But non-query is basically used for executing Update, delete and insert statements.

We cannot execute database job using it

1 Like

Kindly clarify What do you mean by database Job
is it a procedure or function

if Procedure it can be executed with that activity

Cheers @SagarSB

2 Likes

Hi @SagarSB,

As @Palaniyappan said it is right. This is one of way to execute the jobs.

 SqlConnection conn = new SqlConnection("Data Source=<your_db>;Integrated Security=True");
 conn.Open();
SqlCommand cmd = new SqlCommand("msdb.dbo.sp_start_job",conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@job_name", "<your_job_name>");
cmd.ExecuteNonQuery();

So in the Execute Non Query activity.

Parameters and values
~

  • Sql = “msdb.dbo.sp_start_job”
  • Parameter = “your job name”
  • CommandType = StoredProcedure

It will work.

Thank you
Balamurugan.S

3 Likes

Thank you @balupad14 and @Palaniyappan