sp_helptext 输出被 ADO.NET 删除?

发布于 2024-09-01 11:03:34 字数 819 浏览 3 评论 0原文

我正在使用此处描述的工具来清理一些来自我们的开发数据库。我遇到了一个奇怪的问题,但找不到原因。

对于某些存储过程,GetProcedureText 方法(l:47,Validator.cs)无法返回过程文本,导致程序出现意外行为。调试并单步执行 GetProcedureText 时,可以清楚地看到,通过调用 SqlCommand 上的 ExecuteReader 返回的 SqlDataReader 不包含结果集。问题是为什么......

从 SSMS 运行 exec sp_helptext确实会按预期返回 proc 文本。每次相同的过程都会出现问题。下面是展示此问题的过程之一,尽管问题似乎出在 ADO.NET 而不是 SQL Server。

USE [IL_Party_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DeathCause_SelectByDeathCauseCode]
    @deathCauseCode [varchar](15)
AS
SELECT
    death_cause_code,
    description
FROM ilpr_Death_Cause
WHERE
    death_cause_code = @deathCauseCode

我正在使用 SQL Server 2005。有什么想法吗?

I'm using the tool described here to clean up some cruft from our development DBs. I've encountered an odd issue with it and can't find the cause.

For certain stored procedures, the GetProcedureText method (l:47, Validator.cs) fails to return the proc text, causing the program to behave unexpectedly. When debugging and stepping into GetProcedureText it becomes clear that the SqlDataReader returned by the call to ExecuteReader on the SqlCommand does not contain a result set. The question is why..

Running exec sp_helptext <proc name> from SSMS does return the proc text as expected. The problem occurs with the same procs every time. Below is one of the procs exhibiting this issue, though the problem does seem to be with ADO.NET rather than SQL Server.

USE [IL_Party_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DeathCause_SelectByDeathCauseCode]
    @deathCauseCode [varchar](15)
AS
SELECT
    death_cause_code,
    description
FROM ilpr_Death_Cause
WHERE
    death_cause_code = @deathCauseCode

I'm using SQL Server 2005. Any ideas?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若水微香 2024-09-08 11:03:34

我遇到了同样的问题。就我而言,它似乎是在对象的 SQL 中出现错误(例如重命名的列或表)时发生的。它将返回一个空结果,然后所有后续对象都将返回一个空结果。我必须为每个数据库对象创建一个新的 SqlConnection 才能使其正常工作。不确定根本原因是什么,但这对我有用......

I ran into the same problem. In my case, it seemed to occur when there was an error in the object's SQL, such as a renamed column or table. It would return an empty result, then all subsequent objects would return an empty result. I had to create a new SqlConnection for each database object to get it to work properly. Not sure what the underlying cause is, but this worked for me...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文