存储的程序可以很好地播放,多年突然出现了

发布于 2025-02-06 09:18:49 字数 1231 浏览 2 评论 0原文

我有一个大约20岁的数据库,当然不断发展。它的主要功能是成为Web应用程序的后端。所述Web应用程序的一部分停止工作,用户开始致电,我能够指出对存储过程的调用正在计时。应用程序上的其他所有内容都很好(或者至少我希望,这是我问题的一部分。我想我应该说我检查的所有内容都可以运行。我检查了服务器,没有锁,块或许多运行的东西。

我改变了分配传递的变量,转换为新创建的“本地”变量,并更改了代码中使用的所有位置。点击F5,现在又起作用了。

旧示例代码:

ALTER PROCEDURE [dbo].[usp_sprocThatHasBeenFineForYears]
    -- Add the parameters for the stored procedure here
    @TheId int,
    @StartDate datetime

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT * FROM aTable WHERE TheId = @TheId AND StartDate = @StartDate

新示例代码:

ALTER PROCEDURE [dbo].[usp_sprocThatHasBeenFineForYears]
    -- Add the parameters for the stored procedure here
    @TheId int,
    @StartDate datetime

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DECLARE @LOCAL_TheId int = @TheId
    DECLARE @LOCAL_StartDate datetime = @StartDate

    SELECT * FROM aTable WHERE TheId = @LOCAL_TheId AND StartDate = @LOCAL_StartDate

我的问题是:
1-为什么在10年左右的忠实服务之后,这会发生“蓝色”?
2-任何方法可以判断用户尚未发现的其他大楼吗?
3-将来有什么方法可以防止这种情况?

I have a database that's about 20 years old, constantly evolving of course. It's main function is to be the backend for a Web App. One section of said Web App stopped working, users started calling, and I was able to pinpoint that a call to a stored procedure was timing out. Everything else on the App was fine (or at least I hope so, that's part of my question. I guess I should say everything I checked was running fine.) I called the sproc from my local SQL Server Management Studio and it worked fine. I checked the server, there were no locks, blocks, or many things running.

I made the change of assigning the variables being passed in, to newly created "local" variables and changed all the places they were used in the code. Hit F5 and now it works again.

Old sample code:

ALTER PROCEDURE [dbo].[usp_sprocThatHasBeenFineForYears]
    -- Add the parameters for the stored procedure here
    @TheId int,
    @StartDate datetime

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    SELECT * FROM aTable WHERE TheId = @TheId AND StartDate = @StartDate

New Sample code:

ALTER PROCEDURE [dbo].[usp_sprocThatHasBeenFineForYears]
    -- Add the parameters for the stored procedure here
    @TheId int,
    @StartDate datetime

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DECLARE @LOCAL_TheId int = @TheId
    DECLARE @LOCAL_StartDate datetime = @StartDate

    SELECT * FROM aTable WHERE TheId = @LOCAL_TheId AND StartDate = @LOCAL_StartDate

My questions are:
1 - why did this happen "out of the blue" after 10 or so years of faithful service?
2 - any way to tell if this is happening to other sprocs that users haven't discovered yet?
3 - any way to prevent this in the future?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文