Set task priority in MS SQL

Sample for ScriptUtils.Thread.Priority | Changes | Purchase | Download


Set task priority in MS SQL 
      Next stored procedure let's you set thread priority in MSSQL. You can use the function to set some task in idle or another priority.
--set idle priority for the task
EXECUTE sp..xp_set_thread_priority -15, 0

--call some SP in idle priority
EXECUTE sp_longrunning

--set default priority
EXECUTE sp..xp_set_thread_priority 
      Be sure you set default thread priority at the end of your SP/SQL batch (execute xp_set_thread_priority without parameters).
--Let's you set thread priority in MSSQL
CREATE PROCEDURE xp_set_thread_priority(@Priority INT = 0, @PriorityBoost INT = 1) AS
  DECLARE @Thread INT, @OLEResult INT, @Out INT

  --Create ScriptUtils.Thread object
  EXECUTE @OLEResult = sp_OACreate 'ScriptUtils.Thread', @Thread OUT
  IF @OLEResult <> 0 
    RAISERROR ('ScriptUtils.Thread cannot be created. Result : 0x%X', 1, 1, @OLEResult)
      --Set priority boost of actual thread
      EXECUTE @OLEResult = sp_OASetProperty @Thread, 'PriorityBoost', @PriorityBoost
      IF @OLEResult <> 0 RAISERROR ('Cannot set PriorityBoost. Result: 0x%X', 1, 1, @OLEResult)

      --Set priority of actual thread
      EXECUTE @OLEResult = sp_OASetProperty @Thread, 'Priority', @Priority
      IF @OLEResult <> 0 RAISERROR ('Cannot set Priority. Result: 0x%X', 1, 1, @OLEResult)

      --Destroy Thread object
      EXECUTE @OLEResult = sp_OADestroy @Thread

Other links for the Set task priority in MS SQL sample


Thread object. Timing informations, priority settings and Ids.


Huge ASP upload is easy to use, hi-performance ASP file upload component with progress bar indicator. This component lets you upload multiple files with size up to 4GB to a disk or a database along with another form fields. Huge ASP file upload is a most featured upload component on a market with competitive price and a great performance . The software has also a free version of asp upload with progress, called Pure asp upload , written in plain VBS, without components (so you do not need to install anything on server). This installation package contains also ScriptUtilities library. Script Utilities lets you create hi-performance log files , works with binary data , you can download multiple files with zip/arj compression, work with INI files and much more with the ASP utility.

© 1996 - 2011 Antonin Foller, Motobit Software | About, Contacts | e-mail:

Other Motobit links:   IISTracer, real-time IIS monitor   ASP file upload - upload files to ASP. 
ActiveX/VBSScript registry editor  ActiveX NT User account manager  Export MDB/DBF from ASP Active LogFile  Email export  ActiveX/ASP Scripting Dictionary object