|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, July 16, 2010 8:44 AM
Points: 13,
Visits: 50
|
|
I want to initiate a Procedure and then return-continue execution. The reasoning behind this is to use SQL Express but because Express does not have an Agent I need to initiate a recurring task somehow. I have an external app feeding data in SQL so I am hoping there is a way, as part of the call by that external app, that I can initiate a 'task'.
I am sure this is a fairly common need with SQL Express - ideas will be great.
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 12:19 PM
Points: 13,371,
Visits: 25,144
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, January 07, 2010 2:19 PM
Points: 27,
Visits: 34
|
|
| If you are programming using a multithreaded environment like java or .net you can just run the long running query from a new thread. If you're in a single thread environment you have a lot less options.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 12:30 PM
Points: 32,893,
Visits: 26,770
|
|
robertcaustin (5/12/2008) I want to initiate a Procedure and then return-continue execution. The reasoning behind this is to use SQL Express but because Express does not have an Agent I need to initiate a recurring task somehow. I have an external app feeding data in SQL so I am hoping there is a way, as part of the call by that external app, that I can initiate a 'task'.
I am sure this is a fairly common need with SQL Express - ideas will be great.
Hey folks... does SQL Express have Osql.exe? If so, couldn't Robert create a batch file and use Windows Task Scheduler to execute it on a regularly scheduled basis?
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 12:19 PM
Points: 13,371,
Visits: 25,144
|
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, January 07, 2010 2:19 PM
Points: 27,
Visits: 34
|
|
| If its just a matter of running a batch process regularly an executable or batch file started from scheduled tasks would work just fine.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
Another thing you can do is create a startup proc, and use the WaitFor command and a While loop to make it execute something over and over again.
While 1 = 1 begin exec dbo.RecurringCommandProc waitfor delay '00:05' end
That will make it run every 5 minutes. (Well, after it finishes, there will be a 5 minute delay till it runs again. Not the same as starting it every 5 minutes.)
sp_procoption will set it to run automatically at startup. Has to be created in master database and be owned by sa account.
I just tested this in an instance of Express and it seems to have worked.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, July 16, 2010 8:44 AM
Points: 13,
Visits: 50
|
|
Thanks to all the replies but I think my logic and reasoning is the opposite to normal programming. I live inside SQL and only write or use outside programs when I can't do it in SQL. My logic is that locks and DB activity is easiest managed from within the SQL structures. Having an outside program pushing instructions in means a lot of overhead needed to make sure that external process does not mess with the core activity.
So the idea is to run the normal insert process (from an external app) and to return to the external app. But if the insert required some further processing then I want to be able to leave this running as an internally-originated thread/process without holding up the external app.
Hence the thought that it may be possible to call a Stored Procedure from another proc with a flag to run in the background.
I have an existing C Service running on the server that calls for any data that needs to be pushed out to the client. I wanted to use this as a 'timer' to initiate any pending processing BUT I don't want to stall this service while it waits for an unrelated process to complete.
On my Normal (as opposed to SQL Express) servers I have a SQL Agent Task that starts when SQL Starts and is set to restart every minute but because it never ends, it only restarts if the {code} fails While 1=1 begin {code} WAITFOR() end
Express does not have Agent so there is nothing that can initiate this process that does not 'hang' whatever was used to initiate it.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Monday, May 06, 2013 1:09 PM
Points: 15,439,
Visits: 9,569
|
|
Did you look at the startup proc idea I wrote up? That doesn't require any outside process, nor SQL Server Agent.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 12:30 PM
Points: 32,893,
Visits: 26,770
|
|
robertcaustin (5/15/2008) Thanks to all the replies but I think my logic and reasoning is the opposite to normal programming. I live inside SQL and only write or use outside programs when I can't do it in SQL. My logic is that locks and DB activity is easiest managed from within the SQL structures. Having an outside program pushing instructions in means a lot of overhead needed to make sure that external process does not mess with the core activity.
You're a man after my own heart, Robert. Sorry I can't help on the express side of the house.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|