← Tutti gli articoli

Error converting data type decimal to decimal

29 April 2011  ·  Troubleshooting · Article  ·  992 visite

Migration from MS SQL Server 2008 to 2008 R2 - Language Integrated Query - LINQ

I have the following store procedure:
 
  1. procedure [dbo].[sp_SpidBustaGet_RBM] ( @ID_SpidBustaPaga  int , @NumeroMesi  int , @Euro money  out , @Valuta money  out , @rfr  decimal (18,3)  out , @val_cod_valuta  char (3)  out  )  
  2.   
  3.   
  4. //The Linq mapping is:   
  5.   
  6.   
  7. [Function(Name="dbo.sp_SpidBustaGet_RBM")]  
  8.     public int sp_SpidBustaGet_RBM([Parameter(Name="ID_SpidBustaPaga", DbType="Int")] System.Nullable<int> iD_SpidBustaPaga, [Parameter(Name="NumeroMesi", DbType="Int")] System.Nullable<int> numeroMesi, [Parameter(Name="Euro", DbType="Money")] ref System.Nullable<decimal> euro, [Parameter(Name="Valuta", DbType="Money")] ref System.Nullable<decimal> valuta, [Parameter(DbType="Decimal")] ref System.Nullable<decimal> rfr, [Parameter(DbType="Char(3)")] ref string val_cod_valuta)  
  9.     {  
  10.         IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), iD_SpidBustaPaga, numeroMesi, euro, valuta, rfr, val_cod_valuta);  
  11.         euro = ((System.Nullable<decimal>)(result.GetParameterValue(2)));  
  12.         valuta = ((System.Nullable<decimal>)(result.GetParameterValue(3)));  
  13.         rfr = ((System.Nullable<decimal>)(result.GetParameterValue(4)));  
  14.         val_cod_valuta = ((string)(result.GetParameterValue(5)));  
  15.         return ((int)(result.ReturnValue));  
  16.     }  

I have the 3 nullable output parameter: euro , valuta and _rfr

The previous Sql Server 2008 worked fine with the following initialization:

decimal? euro = 0, valuta = 0, decimal? _rfr = 0;

n = linqContra.sp_SpidBustaGet_RBM(ID_SpidBustaPaga, 12, ref  euro, ref  valuta, ref _rfr, ref val_cod_valuta);


in the R2 I have a decimal to decimal convert data type error.

 

Solution:

Set the output parameters to null:

decimal? euro = null, valuta = null, decimal? _rfr = null;

 

Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.