Solved

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

Posted on 2013-11-10
3
939 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
ID: 39637764
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
ID: 39676664
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
ID: 39686702
It is perfectly working as expected
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

14 Experts available now in Live!

Get 1:1 Help Now