简体   繁体   English

存储过程失败,但在手动运行时可正常工作

[英]Stored procedure fails, but works correctly when it runs manually

I have a stored procedure in SQL Server 2008 R2. 我在SQL Server 2008 R2中有一个存储过程。 It was working correctly, but it stopped working (I did not change the code). 它工作正常,但它停止工作(我没有更改代码)。

It is something difficult to explain, specially because I can not share the stored procedure's code (company's rules). 这很难解释,特别是因为我无法共享存储过程的代码(公司规则)。 I will try to explain it as much as possible. 我将尝试尽可能地解释它。

This stored procedure is executed by a software, this software calls two stored procedures. 该存储过程由软件执行,该软件调用两个存储过程。 One of the stored procedures works correctly and the another one "fails" (it doesn't do anything and not return any error). 其中一个存储过程正常工作,另一个存储过程“失败”(它不执行任何操作而不返回任何错误)。 Both stored procedures do similar things such as update and insert information, from parameters, in some tables. 两个存储过程在某些表中执行类似的操作,例如更新和插入信息,来自参数。 If I check the software's logs I can see that this software is calling both stored procedures correctly. 如果我检查软件的日志,我可以看到该软件正在正确调用两个存储过程。 In fact, the stored procedure does not return any error, it just does not do anything. 实际上,存储过程不会返回任何错误,它只是没有做任何事情。

When I run this stored procedure manually, I use the same parameters that the software should pass and it works correctly. 当我手动运行此存储过程时,我使用与软件应该通过的相同参数并且它可以正常工作。

I simulated a real case and the software called both stored procedures, one works and the another one did not do anything. 我模拟了一个真实案例,软件调用了两个存储过程,一个工作,另一个没有做任何事情。 Then, I executed the second stored procedure manually with the same parameters and it worked correctly. 然后,我使用相同的参数手动执行第二个存储过程,它正常工作。

In addition, the database's user has enough permission (I guess it, because it was working correctly). 此外,数据库的用户有足够的权限(我猜它,因为它正常工作)。

Another important thing is that I have two environments with the same databases. 另一个重要的事情是我有两个具有相同数据库的环境。 The software calls both stored procedures in both environments. 该软件在两个环境中调用两个存储过程。 In one of the environments it works correctly and the another environment the software calls both stored procedures, but one of them does not do anything as I have explained here. 在其中一个环境中它正常工作,另一个环境是软件调用两个存储过程,但其中一个没有做任何事情,正如我在这里解释的那样。

Regards and thanks! 问候并感谢!

First, try to run the stored proc using Profiler to get exactly what is being sent, it may not be sending what you think it should. 首先,尝试使用Profiler运行存储过程以准确获取正在发送的内容,它可能不会发送您认为应该发送的内容。

Next check the structure of the two databases for the tables/views referenced, any functions in the procs. 接下来检查引用的表/视图的两个数据库的结构,procs中的任何函数。 Make sure to also check permissions. 确保还要检查权限。 Script the stored procs in both databases and compare. 在两个数据库中编写存储过程的脚本并进行比较。 When database on two servers have an issue like this it is often that the servers are not in sync with the exact code they should have. 当两台服务器上的数据库出现类似问题时,通常服务器与它们应具有的确切代码不同步。

Also the data may be different resulting in no data that needs to be acted on by the stored proc in one server. 此外,数据可能不同,导致在一个服务器中没有需要由存储过程操作的数据。

One reason this can happen is the use of temp tables; 这可能发生的一个原因是使用临时表; if they are not available, it may fail, and the scope works differently in a stored procedure than in an interactive session. 如果它们不可用,则可能会失败,并且范围在存储过程中的工作方式与在交互式会话中的工作方式不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM