类型与创建CLR存储过程不匹配 [英] Types don't match for creating a CLR Stored Procedure
本文介绍了类型与创建CLR存储过程不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在程序集中有一个如下所示的方法:
I have a method in an assembly that looks like this:
namespace MyNameSpace
{
public class MyClass
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void MyMethod(SqlChars myMessage)
{
// Stuff here
}
}
}
我将其编译为一个dll,然后将其加载到我的SQL Server中:
I compile that to a dll and load it into my SQL Server like this:
drop assembly MyAssembly
create assembly MyAssemblyfrom 'C:\Scripts\MyAssembly.dll'
一切正常.
但是现在我尝试运行该命令:
But now I try to run this:
CREATE PROCEDURE MySproc @message nvarchar(max)
AS EXTERNAL NAME MyAssembly.[MyNameSpace.MyClass].MyMethod
运行时出现此错误:
"MySproc"的创建过程失败,因为参数"@myMessage"的T-SQL和CLR类型不匹配.
CREATE PROCEDURE for "MySproc " failed because T-SQL and CLR types for parameter "@myMessage" do not match.
有什么想法可以解决这个问题吗?
我还尝试了以下方法签名:
I have also Tried these method signatures:
-
公共静态无效MyMethod(字符串myMessage)
-
公共静态无效MyMethod([SqlFacet(MaxSize = -1)]字符串myMessage)
推荐答案
Sql类型 nvarchar
映射到CLR(.Net)类型 SqlString
:
Sql type nvarchar
maps to CLR (.Net) type SqlString
:
public static void MyMethod(SqlString myMessage)
{
if (! myMessage.IsNull)
{
String myMessageString = myMessage.ToString();
// Do stuff
}
}
这篇关于类型与创建CLR存储过程不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文