Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How can i run SQL server 2005 Job using vb.net
 

How can i run SQL server 2005 Job using vb.net

How can i run SQL server 2005 Job using vb.net
Ather
Ather.Abbas  Wednesday, August 19, 2009 11:10 AM

Hi Ather.Abbas,

We can call the sp_start_job stored procedure to start a job. This is the detail:
http://msdn.microsoft.com/en-us/library/ms186757(SQL.90).aspx.

This sample shows how to call a stored procedure in VB.Net:
'Create a connection.

Dim connectionString As String = "Data Source=localhost;Initial Catalog=MyDB;Integrated Security=True"

Dim con As SqlConnection = New SqlConnection(connectionString)

'Open the connection.

con.Open()

'Create the command

Dim cmd As SqlCommand = New SqlCommand()

cmd.CommandText = "sp_start_job"

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.AddWithValue("@job_name", "N'Weekly Sales Data Backup'")

'Execute the command.

cmd.ExecuteNonQuery()

'Close the connection.

con.Close()

These are some links about Sql Server Agent Job:

1. How to: Schedule a Job (SQL Server Management Studio):

http://msdn.microsoft.com/en-us/library/ms191439.aspx.

2. How to: Create a Transact-SQL Job Step (SQL Server Management Studio):

http://msdn.microsoft.com/en-us/library/ms187910.aspx.

Let me know if this helps.

Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, August 21, 2009 3:03 AM
I'm not sure what you mean by the term "job" in this context.

You want to call a stored procedure?
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
DeborahK  Wednesday, August 19, 2009 3:10 PM
i mean JOB in SQL server. A SQL Server job is a collection of steps executed by the database engine by SQL Server Agent.
Ather
Ather.Abbas  Thursday, August 20, 2009 9:30 AM

Hi Ather.Abbas,

We can call the sp_start_job stored procedure to start a job. This is the detail:
http://msdn.microsoft.com/en-us/library/ms186757(SQL.90).aspx.

This sample shows how to call a stored procedure in VB.Net:
'Create a connection.

Dim connectionString As String = "Data Source=localhost;Initial Catalog=MyDB;Integrated Security=True"

Dim con As SqlConnection = New SqlConnection(connectionString)

'Open the connection.

con.Open()

'Create the command

Dim cmd As SqlCommand = New SqlCommand()

cmd.CommandText = "sp_start_job"

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.AddWithValue("@job_name", "N'Weekly Sales Data Backup'")

'Execute the command.

cmd.ExecuteNonQuery()

'Close the connection.

con.Close()

These are some links about Sql Server Agent Job:

1. How to: Schedule a Job (SQL Server Management Studio):

http://msdn.microsoft.com/en-us/library/ms191439.aspx.

2. How to: Create a Transact-SQL Job Step (SQL Server Management Studio):

http://msdn.microsoft.com/en-us/library/ms187910.aspx.

Let me know if this helps.

Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, August 21, 2009 3:03 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGrid -> Column inivisibility
• Bound Formatted Textbox Not Accepting New Value
• Converting a DataGridViewImageColumn when the data is string and not an Image
• SortGlyphDirection ignored for .DataSource = DataTabe or DataView
• DataGrid word wrapping
• saving busniess object using a bindingsource
• Make Enter Key Move to Next Column
• DataGrid: Automatically adjust column widths.
• combobox text member from two columns
• ListView scrollbar