Run SQL Process at specific time - sql

I'm trying to build a background process that will check and execute a stored procedure (SQL Server 2008R2) that users will schedule on a UI application. I don't want to create a job, I want to handle it myself. So I was planning to run a check every 2 secs for example and check if there is process that rich the specific time and run it.
Is there any better way to do it?

If you don't want to set up a task within SQL Server, you could write an app that makes the DB call, then schedule that app through Windows Task Scheduler.

Related

Running Sql Scripts On The Start Of The Application

Hi Guys i wanna know how to run few sql script on our application startup
i am using windows Forms to create a desktop application and have to use this approach for certain task.
database server used is MS SQL
we have to make a method which call the DB script then script will run and do his work. if your next process is depend on that particular script then you have to first call the script and do your work if your next action is not depend on that script so you can keep those script in thread and you can do your work so it will not take a time to load your start point

what is the best way to run Sql Agent job using C#?

I am using Sql server 2005 and using C#/Asp.Net 4.0 for UI.
I want to trigger the sql job from an user action in a webpage. I need to keep checking job's status while its running. There are several old threads on this issue which gets the status of the jobs (How to monitor SQL Server Agent Job info in C#) but i need my program should be able to Run,Stop,Enable,Disable the jobs
I need the below functionality in my UI.
Check the status of a sql job
Run the specified job
Stop the job
Disable/Enable the job
You can use the following system stored procedures:
sp_start_job - start an Agent job
sp_stop_job - stop an Agent job
sp_update_job - enable/disable an Agent job
Update:
If you really want to use SMO instead, best place to check out is this MSDN reference. The Job class allows you to do all this.

Scheduled program VB.NET

I would like to ask for a recommendation for my project.
Basically, it's a scheduled program that shall run at a given period of time, for example,
6:00 pm daily, it includes importing an excel file and inserting it in a sql table.
I have my codes with me, but I dont know how to execute this program automatically.
can you give me some advice
I'm using MSSQL2005 server. And VB.NET language.
Build your application to an executable that just does the task once and use Windows task scheduler.
In my old shop, we occassionally forgot about the one-off tasks running under Task SCheduler, but we had lots of SQL Agent jobs running nightly or weekly. So, just to keep things all together, we created SQL Agent jobs for things like this. So my answer is the same as Bala's, but I would trigger the app through a job on SQL Server instead.
How? Take a look at this: http://bp0.blogger.com/_mDuWqJiJyXE/SB6fy1yBRfI/AAAAAAAAATc/bmdxxAfFTjc/s1600-h/JS_Steps1.png
You could use Visual Studio to create windows service which performs the timed actions...it's a steeper learning curve though.

Run application in response to database event

I have a an application that needs to run at the end of a series of database jobs in SQL Server 2005. The application will do processing on the data that was created by these jobs.
What would be the best way to trigger the execution of this application?
Depending on the type of application, if it's non-interactive then you can write CLR stored procedure that can be executed like any other stored procedure call.
If you don't mind having the application run on the database server, just add a new job step and execute it as part of the job. The command type is "operating system command (CmdExec).

Is it possible to automate MS SQL Server (2005) queries via SQL Server Management Studio?

I have two queries saved on my SQL Server 2005 and I would like to have them running at certain intervals, e.g. every 24 hours. Is there a way to automate these queries and schedule them via SQL Server Management Studio?
You need to use the SQL Server Agent, installed as part of SQL Server. This is the background service that's responsible for running scheduled maintenance and backup tasks.
Expand the SQL Server Agent node in SQL Server Management Studio, you should see a tree node called "Jobs"
Right-clicking this will give you the option to add a new job. Jobs consist of a series of steps to be executed in order, and when you add a new step to your job, you can choose various types of step, including "Transact-SQL Script"
Create a new job, add a single T-SQL step, put the queries that you want to run into the step properties, and then use the "Schedule" option in the Job properties to create a recurring schedule that'll run the job every 24 hours (or whenever).
You can use the SQL Server Agent, which will allow the server to run the script/stored procedure.
You can also use the Windows Task Scheduler, either on the server or on any other server or workstation to schedule isqlw/sqlcmd to execute your script/stored procedure.
Create a job with a step in which you execute your queries; the job can be scheduled at your needs.
At a previous employer the operations department had a task sheduling application. They prefered to use the command line tools that come with sql server to execute jobs (stored procedures) on a scheduled basis. This way the "task scheduling application" could recieve an exit status (pass/fail, ok/error) and hold up dependent jobs.
I'm sorry I don't remember the name of the command line tool, but it was part of the sql server distro. I also do not remember the name of the task scheduling application. It was not the windows task scheduler. It was something enterprise level used to manage the nightly cycle.
Not sure of the scale of your project, but this is another way to go.
SKapsal's comment on a command line tool for executing SQL commands is a reference to osql (for SQL2000) or sqlcmd (for SQL2005+). You could save your script a file and run it from that command line using Windows Task Scheduler or something similar.
SQL Agent is still the preferred solution, however, as it provides GUI controls for job creation, scheduling, logging and viewing job execution history/results.
how to schedule a job for sql query to run daily?
This is similar question with helpful answer.
Covering simple step by step manual.