【发布时间】:2014-04-10 02:05:16
【问题描述】:
在 CLR 过程中,我有以下方法:
private static void EndOwnershipForTeam(long assetId, int teamId)
{
const string storedProcedureName = @"up_RemoveAssetOwnershipFromTeam";
using (var connection = new SqlConnection("context connection=true"))
using (var command = new SqlCommand(storedProcedureName, connection))
{
command.Parameters.AddWithValue("assetId", assetId);
command.Parameters.AddWithValue("teamId", teamId);
connection.Open();
command.ExecuteNonQuery();
}
}
当我运行此方法时,我收到以下错误:
消息 6522,级别 16,状态 1,过程 cp_RemoveAsset,第 0 行
在执行用户定义的例程或聚合“cp_RemoveAsset”期间发生 .NET Framework 错误:
System.Data.SqlClient.SqlException:过程或函数“up_RemoveAssetOwnershipFromTeam”需要参数“@assetId”,但未提供。
System.Data.SqlClient.SqlException:
在 System.Data.SqlClient.SqlConnection.OnError(SqlException 异常, Boolean breakConnection)
在 System.Data.SqlClient.SqlCommand.RunExecuteNonQuerySmi(Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult 结果, String methodName, Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在 StoredProcedures.EndOwnershipForTeam(Int64 assetId, Int32 teamId)
在 StoredProcedures.cp_RemoveAsset(SqlInt32 userId, SqlString xaid)
既然我的代码提供了参数(通过SqlContext.Pipe.Send() 调用显示输出来验证),为什么它声称我没有提供我实际提供的参数?
【问题讨论】:
-
您的 proc 是否调用任何其他程序?如果是这样,我会检查您是否正确地向那些提供参数。
-
指定命令类型:
command.CommandType = CommandType.StoredProcedure;