In a CLR procedure I have the following method:
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();
}
}
When I run this method is called I am getting the following error:
Msg 6522, Level 16, State 1, Procedure cp_RemoveAsset, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "cp_RemoveAsset":
System.Data.SqlClient.SqlException: Procedure or function 'up_RemoveAssetOwnershipFromTeam' expects parameter '@assetId', which was not supplied.
System.Data.SqlClient.SqlException:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQuerySmi(Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at StoredProcedures.EndOwnershipForTeam(Int64 assetId, Int32 teamId)
at StoredProcedures.cp_RemoveAsset(SqlInt32 userId, SqlString xaid)
Since my code is supplying the parameters (verified by displaying output via SqlContext.Pipe.Send()
calls) why is it claiming that I"m not supplying a parameter I actually am?