I have a stored procedure which executes another procedure inside it. The second one sometimes takes a while to run but the first seems to finish before waiting for the second. This has resulted in missing data, which should have been updated by the second procedure. Is there a timeout limit within the first procedure and can this be extended?
我有一个存储过程,在其中执行另一个过程。第二个有时需要一段时间才能运行,但第一个似乎在等待第二个之前完成。这导致数据丢失,应该由第二个程序更新。第一个程序中是否有超时限制,可以延长吗?
3 个解决方案
#1
2
create a new table:
创建一个新表:
LogInfo
LogID int auto number/identity primary key
LogDate date default current date and time
LogValue string
in each procedure add INSERTs like this:
在每个过程中添加这样的INSERT:
INSERT INTO LogInfo (LogValue) VALUES ('starting procedure A')
...
INSERT INTO LogInfo (LogValue) VALUES ('Calling procedure B')
...
INSERT INTO LogInfo (LogValue) VALUES ('ending procedure A')
then do this
然后这样做
SELECT * FROM LogInfo ORDER BY LogID
to see what happened, hopefully you will see this because procedures run sequentially and B can not finish after A:
看看发生了什么,希望你会看到这个因为程序顺序运行而B在A之后无法完成:
starting procedure A
Calling procedure B
starting procedure B
ending procedure B
ending procedure A
#2
1
I would suspect that the inner stored procedure is in fact finishing/exiting as stored procedures run sequentially and symmetrically.
我怀疑内部存储过程实际上是完成/退出,因为存储过程顺序和对称地运行。
You might try scripting the outer stored procedure and drop it into Management Studio, remove the Create Procedure declaration, replace the arguments with Declare and add SET statements to set them to the values you are using on your test run. In addition, put Print statements after the call to the inner stored procedure and see if it completes.
您可以尝试编写外部存储过程的脚本并将其放入Management Studio,删除Create Procedure声明,使用Declare替换参数并添加SET语句以将它们设置为您在测试运行中使用的值。另外,在调用内部存储过程之后放置Print语句并查看它是否完成。
#3
1
You are understandably mistaken. Stored procedures execute synchcronously. For a variety of reasons, however, the results of the inner procedure may not be visible to an external process until after they have actually occurred. This may be why you are seeing whatever you are seeing that leads you to belive the order of completion is not in synch.
你可以理解是错的。存储过程同步执行。然而,由于各种原因,内部过程的结果可能在外部过程实际发生之后才可见。这可能就是为什么你看到你所看到的任何导致你相信完成顺序不同步的原因。
#1
2
create a new table:
创建一个新表:
LogInfo
LogID int auto number/identity primary key
LogDate date default current date and time
LogValue string
in each procedure add INSERTs like this:
在每个过程中添加这样的INSERT:
INSERT INTO LogInfo (LogValue) VALUES ('starting procedure A')
...
INSERT INTO LogInfo (LogValue) VALUES ('Calling procedure B')
...
INSERT INTO LogInfo (LogValue) VALUES ('ending procedure A')
then do this
然后这样做
SELECT * FROM LogInfo ORDER BY LogID
to see what happened, hopefully you will see this because procedures run sequentially and B can not finish after A:
看看发生了什么,希望你会看到这个因为程序顺序运行而B在A之后无法完成:
starting procedure A
Calling procedure B
starting procedure B
ending procedure B
ending procedure A
#2
1
I would suspect that the inner stored procedure is in fact finishing/exiting as stored procedures run sequentially and symmetrically.
我怀疑内部存储过程实际上是完成/退出,因为存储过程顺序和对称地运行。
You might try scripting the outer stored procedure and drop it into Management Studio, remove the Create Procedure declaration, replace the arguments with Declare and add SET statements to set them to the values you are using on your test run. In addition, put Print statements after the call to the inner stored procedure and see if it completes.
您可以尝试编写外部存储过程的脚本并将其放入Management Studio,删除Create Procedure声明,使用Declare替换参数并添加SET语句以将它们设置为您在测试运行中使用的值。另外,在调用内部存储过程之后放置Print语句并查看它是否完成。
#3
1
You are understandably mistaken. Stored procedures execute synchcronously. For a variety of reasons, however, the results of the inner procedure may not be visible to an external process until after they have actually occurred. This may be why you are seeing whatever you are seeing that leads you to belive the order of completion is not in synch.
你可以理解是错的。存储过程同步执行。然而,由于各种原因,内部过程的结果可能在外部过程实际发生之后才可见。这可能就是为什么你看到你所看到的任何导致你相信完成顺序不同步的原因。