久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何用另一個(gè)存儲(chǔ)過程執(zhí)行一個(gè)存儲(chǔ)過程?

How to execute a stored procedure with another stored procedure?(如何用另一個(gè)存儲(chǔ)過程執(zhí)行一個(gè)存儲(chǔ)過程?)
本文介紹了如何用另一個(gè)存儲(chǔ)過程執(zhí)行一個(gè)存儲(chǔ)過程?的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有會(huì)話鎖定程序,它執(zhí)行一個(gè)程序在一個(gè)會(huì)話中運(yùn)行時(shí)的操作,如果同一個(gè)程序正在另一個(gè)會(huì)話中運(yùn)行,則在第一個(gè)會(huì)話完成之前它不會(huì)執(zhí)行

I have session lock procedure which do the action of when one procedure is running in one session if the same procedure is running another session it will not execute until the first session completes

EXEC dbo.[system-LockProcedure]'dbo.usp_Test1' 

它工作正常,我沒有問題,但是當(dāng)我想使用輸入?yún)?shù)執(zhí)行過程時(shí),出現(xiàn)錯(cuò)誤:

It is working fine and I have no issues but when I want to execute procedure with input parameters, I get an error:

DECLARE @threadid INT = 0;

EXEC [util].[system-LockProcedure] N'[dbo].[usp_Test1] @threadid=@threadid', 
                       N'@threadid INT', 
                         @threadid=@threadid

錯(cuò)誤:

[dbo].[usp_Test1] 需要參數(shù) @threadid,但未提供.

[dbo].[usp_Test1] expects parameter @threadid, which is not supplied.

當(dāng)我執(zhí)行一個(gè)沒有輸入?yún)?shù)的過程時(shí),它工作正常,當(dāng)我想執(zhí)行一個(gè)帶有輸入?yún)?shù)的過程時(shí),它會(huì)拋出一個(gè)錯(cuò)誤.

When I'm executing a procedure with no input parameters it is working fine and when I want execute a procedure with input parameters, it throws an error.

請建議如何解決這個(gè)問題.

Please suggest how to fix this.

系統(tǒng)鎖定程序:

CREATE Procedure [dbo].[system-LockProcedure] @procname varchar(200)

AS 

--BEGIN TRAN
BEGIN

DECLARE @lockreturn int,
        @lockresource varchar(200)               --sysname


SELECT @lockresource =    @procname    



              -- The below line will try to acquire an exclusive lock on the PROC for the session, If the Proc is already in execution the @lockreturn value will be > 0

                 EXEC @lockreturn = sp_getapplock @lockresource, @LockMode = 'Exclusive', @LockOwner = 'Session'  , @LockTimeout = 100
                                                                Print @lockreturn 

                 IF @lockreturn <> 0
                 BEGIN

                        RAISERROR ('Another instance of the procedure is already running', 16, 1)
                                                                                                RETURN
                 END

                -- The Code to be executed goes here. All the core logic of the proc goes here..

              Print 'Procedure Execution Started for user: ' +  cast (CURRENT_USER as nvarchar(20))+ ' for session: ' + cast (@@SPID as nvarchar(10))

                -- This is just to make the system wait for 30 seconds and make sure if there is any concurrent execution triggered will fail

                                                                exec @lockresource

              Print 'Procedure Execution Ended for user: ' +  cast (CURRENT_USER as nvarchar(20))+ ' for session: ' + cast (@@SPID as nvarchar(10))

                                                  Print @lockreturn

                -- This is to release the lock once the SP code is ran completely

                                                EXEC sp_releaseapplock @lockresource , 'Session'

                                                 -- END TRY


    END

推薦答案

試試這個(gè):

DECLARE @threadid INT = 0;

DECLARE @ExecuteString NVARCHAR(MAX) = N'[dbo].[usp_Test1] @threadid= ' + CAST(@threadid AS VARCHAR(4)) + ';'

EXEC [util].[system-LockProcedure] @ExecuteString;

這篇關(guān)于如何用另一個(gè)存儲(chǔ)過程執(zhí)行一個(gè)存儲(chǔ)過程?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問題和答案的組合))
主站蜘蛛池模板: 久久久精 | 仙人掌旅馆在线观看 | 午夜男人天堂 | 亚洲福利精品 | 91精品欧美久久久久久久 | 91精品久久久久久久久久入口 | 日韩一区二区在线视频 | 国产精品资源在线 | 国产一区二区麻豆 | 欧美a区 | 久久久蜜桃 | 国产精品久久久久久吹潮 | av网站在线看 | 国产视频一区二区三区四区五区 | 国产视频观看 | 九色网址| 免费黄色的视频 | 精品一区视频 | 免费激情av| 91久久精| 亚洲伊人精品酒店 | 亚洲一区av| 成人h动漫精品一区二区器材 | 亚洲+变态+欧美+另类+精品 | 亚洲综合日韩精品欧美综合区 | 91国产在线视频在线 | 婷婷五月色综合香五月 | 日日日操 | h小视频| 久久久久1 | 国产偷录视频叫床高潮对白 | 精品国产一区二区三区性色av | 亚洲九九色 | 亚洲精品视频一区二区三区 | 日韩av在线中文字幕 | 天天干夜夜操 | 久久另类 | 久草.com| 91精品亚洲 | 成人在线精品视频 | 97国产爽爽爽久久久 |