Solved

How to trigger and find status of sql job through c#?

Posted on 2013-11-10
3
916 Views
Last Modified: 2013-11-30
I have an requirement in which SQL server job needs to be trigger through C# and show the status in web application from its start to end.

SQL server job has to fetch data from excel file and loading it to the SQL Server 2008 R2 database which has minimum of 25000 rows and maximum of any.

Please help in resolve this.

Thanks in advance.
0
Comment
Question by:devmasters
  • 2
3 Comments
 
LVL 23

Expert Comment

by:Michael74
Comment Utility
If you create the sql job as a stored procedure you can then use print statements in the proc to provide updates to the web app

http://www.nullskull.com/faq/1131/view-print-statements-in-your-stored-procedures-in-c-via-adonet.aspx

Michael
0
 

Accepted Solution

by:
devmasters earned 0 total points
Comment Utility
SqlConnection DbConn = new SqlConnection(sqlConnection);
            SqlCommand ExecJob = new SqlCommand();
            ExecJob.Connection = DbConn;
            ExecJob.CommandType = CommandType.StoredProcedure;
            ExecJob.CommandText = "msdb.dbo.sp_start_job";
            ExecJob.Parameters.AddWithValue("@job_name", "LoadData");

            using (DbConn)
            {
                DbConn.Open();
                using (ExecJob)
                {
                    ExecJob.ExecuteNonQuery();
                }
            }
0
 

Author Closing Comment

by:devmasters
Comment Utility
It is perfectly working as expected
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now