SQL Server Azure - Executing stored procedure every x minutes - c#

Generally with SQL Server, I could setup a job and have it run every so often. Something like this. However SQL Server Azure does not seem to have this ability.
My thoughts were to instead, have a service that runs this procedure every x minutes. I'm just wondering if anyone sees any issues with that, or has any better suggestions?
The stored procedure takes some xml data stored in one table and normalizes it across other tables making it easier to query on.

You can schedule jobs using the new Scheduler:
http://weblogs.asp.net/scottgu/archive/2012/12/21/great-updates-to-windows-azure-mobile-services-web-sites-sql-data-sync-acs-media-more.aspx
More Detail:
http://www.windowsazure.com/en-us/develop/mobile/tutorials/schedule-backend-tasks/

If you are open to using a service, Cotega offers the ability to schedule execution of stored procedures from within SQL Azure. You can read more about how to schedule these jobs here.
Full disclosure, I work on this service.

You can trigger scheduled task running procedure directly from your application using, for example, Quartz.

Related

Run Azure SQL Server Stored procedure async

I am moving from an onprem SQL Server managed instance to a Azure SQL Database. My issue is that given the lack of a Sql Agent I am forced to run a Azure Function to automate some stored procedures that we`re running.
Here is the issue:
Azure Function cannot run more than 10 minutes (without a big hassle) my archiving job runs for about 40 minutes.
sp_start_job - does not exist in Azure SQL
Trying to find a way to not keep open the connection from Azure function.
Thanks in advance all help is appreciated
I think You could using Data Factory to help you schedule execute the stored procedures.
Create a pipeline with on or more Stored Procedure activities:
Add trigger to schedule the pipeline running:
And #Chetan Ranpariya also provided the good suggestions for you. Ref:
https://learn.microsoft.com/en-us/azure/azure-sql/database/job-automation-overview
https://www.netwoven.com/2017/12/12/schedule-execution-sql-jobs-azure-automation-service/
Hope this helps.

Best way to get an alert soon after data inserted into a SQL Server table

I have a task, in which I have control over the database but not on the application which does CRUD operations on the SQL Server 2008 R2 database.
Ideally, I would like to call (POST) a web API (please note that, I don't have to wait of the API response) soon after an insert operation on the data table.
Things on my mind to achieve this
Create a SQL Server trigger on the data table (CLR enabled but it's SQL Server 2008R2 so it's using .Net 2.0).
I may have to create a stored procedure to call web API (POST) (it should be fire and forget, as I don't have to wait for the API response) as part of the trigger.
Service Broker and Dependency injection alert
---> This works well but I am worried about concurrency.
Traditional polling
Questions: If I go with the first solution, does trigger execute in the same transaction scope as the insert operation? If web API is down, will it delay the insert operation? Does this method handle concurrency?
Is there any other method you would recommend? (Please include pros and cons as part of the solution)
The trouble with triggers is the fact that they execute in the context and scope of the statement that caused them to fire, so a delay in the trigger will slow down / block your actual application. Therefore, you should never do lengthy processing or calling external services inside a trigger.
My approach would be:
have a trigger that's very lean and only makes an INSERT into a separate table (a "command" table or whatever you might call it). This table should contain all the necessary, relevant information for the notification
have a separate, scheduled process - either a scheduled SQL Server job, or an external application on a server - that polls that table on a regular basis - every minute, every 15 minutes - whatever you need - and if there's a new entry in the "command" table, it does what it needs to do and sends out notifications or calls external WebAPI services etc.
With this approach, your system is still as responsive as it can be (not delays by "stuck" triggers), and it gives you the flexibility to schedule that "notification sender" application or SQL job as frequently as you need it.

Looking to run automated jobs in .NET application

Within a .NET application (.NET Framework 4.5), the following is occurring:
A single record in a table in an SQL Server database is referred to as a job
When the job is run, C# code is called
Briefly to explain what it is doing, the job, when run, converts PDFs in a folder directory location, to images in SQL Server
Currently, these jobs run successfully, when the user manually runs them
Does anyone have a recommendation on how these jobs may be run as automated, and not require user intervention? I'm trying to find a process similar to the following:
A daily process will look for all jobs that have a 'next run date' of the current date (the 'next run date' will be stored in a table/column in SQL Server)
When a job is run, the C# code is to be called and run, without user intervention
If you can insert the first part of your requirement (to look for all jobs that have a 'next run date' of the current date (the 'next run date' will be stored in a table/column in SQL Server)) in the C# application that is already executed manually then you only need a Task Scheduler to Execute this C# Application on a daily basis.
you basically need to set up a CRON job. If your "job" can operate on a URL, you could use a service like "easycron.com" to set up a call to this URL at regular intervals.
Alternatively, the same thing might be possible with your hosting if they allow CRON jobs to be set up.
If this isn't a web-facing app - maybe a scheduled task calling the app (if it is a console based EXE) directly on the server. You'll obviously need access to the server at an admin level for that.

how to fire job in sql agent in c# in a fire and forget manner

We have a ssis pkg that takes 20 mins to complete. (generates a xl report). Users had requested ability to control this pkg via params so we have winforms/c# gui that runs the pkg. (Direct from sql server. We basically call a stored proc that starts a sql job that runs the ssis pkg). So far so good. Now users want to log off after submitting the report request since it does not make sense to wait for 20 mins. (we use citrix vdi. Users loginto specific vdi depending on the apps they want to use, do their tasks and logoff). We are 90% there and just for this functionality service broker seems to be an overkill. I checked with our dba and we have never used service broker till now. Is there someway I can get the ssis pkg to run even if the user closed the winforms app and logged off. (basically sql connection is lost but the fired ssis pkg on sql server must continue to run to completion). thanks
we can do like this add package in job call proc and leave it will run
CREATE proc startjob
AS
begin
EXEC dbo.sp_start_job N'Weekly Sales Data Backup'
END

The best way of triggering a timely event

I am building an ASP.Net website, I have a db table which I want to reset a column in it for all rows. column type: byte
I want to do this every day at midnight, in an automatically way. I know I can set a job in SQL Server Management Studio but I want to do this in a programmatic way and my website will be the trigger for it.
I'm using C#.Net 2008 and MS SQL Server 2005
i.e. (Pseudo code)
if(new_day)// can we be accurate that time here will be around 12:00:05 at maximum?
// call sql stored procedure to reset that column
You could make a simple Windows service in C# that would run in the background but considering all you want to do is make database updates, it's best to keep it in the DB....I'd suggest going with the scheduled job in SQL
Your website only executes when a page is requested making it unable to act as a service that executes a task at regular intervals. The best solution is to use SQL Server directly to schedule the task, create your own service or execute an application at regular intervals using Windows task scheduler.
However, if you for are in hosted environment you may not be able to do any of this. In that case you can use the cache to simulate a service. Omar Al Zabir has an article on CodeProject that explains how you can do that: Simulate a Windows Service using ASP.NET to run scheduled jobs.
If you really want to: create a Scheduled Task that calls your website every day at midnight. The website itself cannot trigger itself, but a task can do this.
But really: just set up a SQL job.
SQL Agent job, scheduled to run at the specified time.

Categories

Resources