SQL Server Management Studio 错误:UserDefinedFunction 脚本失败

发布于 2024-12-24 03:07:12 字数 969 浏览 0 评论 0原文

我正在使用 SSMS 处理本地和远程 SQL Server 实例。我创建了一个小函数,例如:

create function ufnTestFunc ()
returns int
begin
    return 1
end

当我尝试“修改”它,或选择“脚本函数为 ->”时更改',我收到如下错误:

UserDefinedFunction“dbo.ufnTestFunc”的脚本失败。 (微软.SqlServer.Smo)

- UserDefinedFunction“ufnTestFunc”的 TextHeader 中存在语法错误。 (微软.SqlServer.Smo)

这也会发生在现有的函数上。可能是什么原因?


注释:

  • 所有函数都按预期工作,
  • 我可以将函数脚本编写为“创建”,没有任何问题。
  • 它与注释无关,因为测试函数中没有注释
  • 远程服务器上的不同数据库也会发生同样的情况

本地服务器:
Microsoft SQL Server Express 版(64 位)- 10.50.2500.0

远程服务器:
Microsoft SQL Server 网络版(64 位)- 10.50.1600.1

SSMS:

Microsoft SQL Server Management Studio    10.50.2500.0
Microsoft Data Access Components (MDAC)   6.1.7601.17514
Microsoft MSXML                           3.0 6.0 
Microsoft .NET Framework                  2.0.50727.5448

I'm working on a local and a remote SQL Server instance with SSMS. I create a tiny function like:

create function ufnTestFunc ()
returns int
begin
    return 1
end

When I try to 'modify' it, or choose 'script function as -> alter', I get an error like:

Script failed for UserDefinedFunction 'dbo.ufnTestFunc'.
(Microsoft.SqlServer.Smo)

- Syntax error in TextHeader of UserDefinedFunction 'ufnTestFunc'.
(Microsoft.SqlServer.Smo)

This also happens on already existing functions. What may be the reason?


Notes:

  • All the functions work as intended
  • I can script the function as 'create' with no problem.
  • It's not related with comments, as there are no comments in the test function
  • Same happens with different DBs on the remote server

Local Server:
Microsoft SQL Server Express Edition (64-bit) - 10.50.2500.0

Remote Server:
Microsoft SQL Server Web Edition (64-bit) - 10.50.1600.1

SSMS:

Microsoft SQL Server Management Studio    10.50.2500.0
Microsoft Data Access Components (MDAC)   6.1.7601.17514
Microsoft MSXML                           3.0 6.0 
Microsoft .NET Framework                  2.0.50727.5448

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

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

发布评论

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

评论(3

水溶 2024-12-31 03:07:12

运行 sp_helptext N'ufnTestFunc'

函数上方的“注释”部分是否有任何看起来奇怪的内容?

嵌入注释 /* */ 有时会导致该错误。

例子:

/* 
    This function does something. 
    /* NOTE: not any useful, though */
    More stuff...
*/
alter function ufnTestFunc ()
returns int
begin
    return 1
end

Run sp_helptext N'ufnTestFunc'

Is there anything in the "comment" section above the function that looks odd?

Embedded comments /* */ can sometimes cause that error.

Example:

/* 
    This function does something. 
    /* NOTE: not any useful, though */
    More stuff...
*/
alter function ufnTestFunc ()
returns int
begin
    return 1
end
落在眉间の轻吻 2024-12-31 03:07:12

好吧,就像之前有人提到的那样,但有一点不同。

问题在于 AS 关键字。尽管函数内容之前的 AS 关键字是可选的,但 SSMS 无法处理没有它的函数。他们工作,却制造麻烦。这是一个错误,并且 BOL 中没有提及。

我通常使用 AS 关键字,但这次数据库来自以前的编码员,他没有使用它。在我的测试函数中,我也没有使用它来使函数尽可能小。

Ok like someone mentioned before, but with a little difference.

The problem is the AS keyword. Although the AS keyword before the function content is optional, SSMS can't handle functions without it. They work, but make trouble. It's a bug and not mentioned anywhere in the BOL.

I normally use the AS keyword, but this time the DB is from a previous coder, who didn't use it. In my test function I also didn't use it to make the function as small as possible.

过期以后 2024-12-31 03:07:12

--补充说我收到了这个错误,既不能编写脚本也不能修改存储过程。

问题是内嵌的块注释部分,位于另一个块注释内。

/*  
Example call:  
 Exec [usp_mySproc] @Param = '172777'  /* blah, blah */
 Exec [usp_mySproc] @Param = '172777', @Debug = 1   WITH RECOMPILE   
*/ 

删除了内部注释块,没有问题。

--Adding that I received this error and could neither script nor modify the sproc.

The problem was a block comment section inline, inside another block comment.

/*  
Example call:  
 Exec [usp_mySproc] @Param = '172777'  /* blah, blah */
 Exec [usp_mySproc] @Param = '172777', @Debug = 1   WITH RECOMPILE   
*/ 

Removed inner comment block and no problem.

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