[英]SQLCLR stored procedure fails to install
I have created a stored procedure in Visual Studio (VS). 我已经在Visual Studio(VS)中创建了一个存储过程。 When I attempt to install the procedure after successfully creating the assembly I get the error: 在成功创建程序集后尝试安装该过程时,出现错误消息:
CREATE PROCEDURE for sp_GetDistanceAndTime failed because T-SQL and CLR types for parameter "@Profile" do not match. sp_GetDistanceAndTime的CREATE PROCEDURE失败,因为参数“ @Profile”的T-SQL和CLR类型不匹配。
How do I get this to install? 我如何安装它? Are my parameters incorrect? 我的参数不正确吗?
C# code: C#代码:
public partial class StoredProcedures
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void SqlStoredProcedure1(SqlString Profile, SqlString StartPosition,
SqlString Destination)
{
try
{
SqlPipe sqlPipe = SqlContext.Pipe;
string result;
result = PTVRequest.InvokeService(Profile.ToString(),
StartPosition.ToString(), Destination.ToString());
SqlContext.Pipe.Send(result);
}
catch (Exception ex)
{
SqlContext.Pipe.Send(ex.Message);
}
}
}
SQL code: SQL代码:
Create Procedure sp_GetDistanceAndTime(@Profile text, @StartPosition text,
@Destination text)
AS
External NAME GetPvt.StoredProcedures.SqlStoredProcedure1
go
TEXT
, NTEXT
, or IMAGE
datatypes. 切勿使用TEXT
, NTEXT
或IMAGE
数据类型。 Those have been deprecated for 13 years now, starting with the release of SQL Server 2005 which introduced the MAX
datatypes to replace those old blob types. 从SQL Server 2005版本开始,已经弃用了13年,SQL Server 2005版本引入了MAX
数据类型来替换那些旧的Blob类型。 CHAR(1 - 8000)
, VARCHAR(1 - 8000)
, or VARCHAR(MAX)
. 因此,您不能使用CHAR(1 - 8000)
, VARCHAR(1 - 8000)
或VARCHAR(MAX)
。 And I don't think it likes NCHAR
either. 而且我也不认为它喜欢NCHAR
。 Your choices are: NCHAR(1 - 4000)
or NVARCHAR(MAX)
. 您可以选择: NCHAR(1 - 4000)
NVARCHAR(MAX)
NCHAR(1 - 4000)
或NVARCHAR(MAX)
。 Both of those map to both SqlString
and SqlChars
. 这些都映射到SqlString
和SqlChars
。 SqlContext.Pipe.Send(string)
is equivalent to using PRINT
in T-SQL. SqlContext.Pipe.Send(string)
等效于在T-SQL中使用PRINT
。 It is just a message that shows up in the "Messages" tab in SSMS. 这只是一条消息,显示在SSMS的“消息”选项卡中。 It is neither a return value nor an OUTPUT
parameter. 它既不是返回值也不是OUTPUT
参数。 A quick example (fix sizes to your case, etc): 一个简单的例子(根据您的情况确定大小等):
public static void SqlStoredProcedure1([SqlFacet(MaxSize=100)] string Profile,
[SqlFacet(MaxSize=200)] string StartPosition,
[SqlFacet(MaxSize=100)] string Destination)
And: 和:
CREATE PROCEDURE sp_GetDistanceAndTime
@Profile nVARCHAR(100), @StartPosition nVARCHAR(200), @Destination nVARCHAR(100)
AS EXTERNAL NAME GetPvt.StoredProcedures.SqlStoredProcedure1
See Mapping CLR Parameter Data for details. 有关详细信息,请参见映射CLR参数数据 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.