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

如何用另一個存儲過程執行一個存儲過程?

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

問題描述

我有會話鎖定程序,它執行一個程序在一個會話中運行時的操作,如果同一個程序正在另一個會話中運行,則在第一個會話完成之前它不會執行

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' 

它工作正常,我沒有問題,但是當我想使用輸入參數執行過程時,出現錯誤:

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

錯誤:

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

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

當我執行一個沒有輸入參數的過程時,它工作正常,當我想執行一個帶有輸入參數的過程時,它會拋出一個錯誤.

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.

請建議如何解決這個問題.

Please suggest how to fix this.

系統鎖定程序:

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

推薦答案

試試這個:

DECLARE @threadid INT = 0;

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

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

這篇關于如何用另一個存儲過程執行一個存儲過程?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
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屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产成人精品999在线观看 | 久久久久九九九女人毛片 | 五月天天色 | 久久国产区 | 欧美成人精品一区二区男人看 | 日本精品视频一区二区 | 久久成人精品视频 | 亚洲欧美综合 | 国产在线精品一区二区 | 国产综合视频 | 最新毛片网站 | 免费视频久久久久 | 国产乱码精品1区2区3区 | 国产一区二区三区免费 | 国产高清在线精品一区二区三区 | 国产三区视频在线观看 | 久久亚洲精品久久国产一区二区 | 国产一二区免费视频 | 国产在线精品一区二区三区 | 狠狠爱免费视频 | 国产99精品| 欧美一级做性受免费大片免费 | 一区二区三区网站 | 久久精品久久精品久久精品 | 久久久久久综合 | 亚洲美女网站 | 日韩高清一区二区 | 久久专区| 青青草视频网站 | 成人在线网址 | 精品粉嫩超白一线天av | 亚洲一区在线观看视频 | www.色五月.com | av三级在线观看 | 国产精品一区二区视频 | 欧美中文在线 | 最新午夜综合福利视频 | 一区二区三区高清在线观看 | 免费黄色片在线观看 | 香蕉久久网 | 黄色免费观看网站 |