Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

sp_getapplock script not working in SSIS(data tools 2012)

$
0
0

Hi,

I have a SSIS package created in 2012 data tools. I have added sql tasks to create and release the locks.

Create the lock script in sql task1:

DECLARE @ProcResult int = 0;

-- Get an exclusive application lock on the package execution resource, to prevent other executions of the same package from doing the same
EXEC @ProcResult = sp_getapplock @Resource ='a',
                                 @LockMode = 'Exclusive',
                                 @LockOwner = 'Session',
                                 @LockTimeout = 0; -- Do not wait for the lock
IF @ProcResult < 0
    RAISERROR('Failed to acquire application lock on %s. sp_getapplock returned %d', 16, 1, @PackageResourceName, @ProcResult);

Release the lock in sql task 2:

DECLARE @ProcResult int = 0;

-- Release a previously acquired exclusive application lock on the package execution resource
EXEC @ProcResult = sp_releaseapplock @Resource ='a',
                                     @LockOwner = 'Session';

IF @ProcResult < 0
    RAISERROR('Failed to release application lock on %s. sp_releaseapplock returned %d', 16, 1, @PackageResourceName, @ProcResult);

When I ran this,  the release lock failing with the following error:

[Execute SQL Task] Error: Executing the query "DECLARE @ProcResult int = 0;

-- Release a previou..." failed with the following error: "Cannot release the application lock (Database Principal: 'public', Resource: 'a') because it is not currently held.
Failed to release application lock on a. sp_releaseapplock returned -999". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

When I use the same above tasks with same scripts in data tools 2010 its working fine. Any thing wrong in 2012 Data tools? 

Please advice. Tx in advance


Porus


Viewing all articles
Browse latest Browse all 24688

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>