J'ai une procédure stockée qui ressemble à ceci: qu'il appelle via System.Data.SqlClient
Int64 qui exerce la contrainte à l'octet [] dans l'appel de procédure stockée
create procedure [dbo].[Batch_of_Things_Get] (@MaxTimestamp binary(8)) as
begin
set nocount on
select top 3500
i.ThingID,
i.Name,
i.CreationDate,
i.local_timestamp
from
[dbo].[Thing] i
where
i.local_timestamp > @MaxTimestamp
end
et du code C# (.NET 3.5), en utilisant un Pour le paramètre @MaxTimestamp
.
public static string GetUpdatedThings(long MinTimestamp)
{
// the ExecuteXmlDocument call takes: string SPName, params object[] SPParams
return new SqlProcedure(Config.ConnectionString).ExecuteXmlDocument("Batch_of_Things_Get", MinTimestamp).OuterXml;
}
Il travaillait (et même travaille encore tout à fait avec bonheur dans la production), mais ma copie dev jette maintenant:
InvalidCastException: Impossible de convertir la valeur de paramètre à partir d'un Int64 à un octet [ ]
StackTrace:
at System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType)
at System.Data.SqlClient.SqlParameter.GetCoercedValue()
at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters)
at System.Data.SqlClient.SqlCommand.BuildRPC(Boolean inSchema, SqlParameterCollection parameters, _SqlRPC& rpc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteXmlReader()
Maintenant, je peux comprendre pourquoi cela échoue maintenant, mais pourquoi pas plus tôt? Editer: J'ai changé le code C# pour convertir le long en Byte [], maintenant il lance: Failed to convert parameter value from a Byte[] to a Int64.
, ce qui est le contraire de ce dont il se plaignait initialement!
Qu'est-ce que le look de code C# comme? Utilise-t-il la classe 'BitConverter'? –
ajouté le code C# ... – geofftnz
a fini par écrire une solution de contournement où je spécifie explicitement les noms et les types de paramètres SP. – geofftnz