Workaround “The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect” error.

We have a .Net 1.1 application that worked with SQL server 2000. When we changed it to work with sql Server 2005, some calls to SPs returned errors like the following

The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 8 (“@ParamName”): The supplied value is not a valid instance of data type numeric. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.”

It was found, that C# decimal variable can keep values with more than 4 decimal points (e.g. 43.23232322323) and when it is passes to SP parameter as MONEY, combination .Net 1.1 – SQL Server 2005 doesn’t work.
Note that combination  .Net 1.1 – SQL Server 2000 and  .Net 2.0 – SQL Server 2005  work fine.

To workaround I’ve added simple function to round values before assigning SP parameter

       public static decimal SafeMoney(object attribute)
        {
            decimal decMoney = Convert.ToDecimal(attribute);
            decMoney = Math.Round(decMoney, 4);//required in 1.1 to connect to SQL Server 2005
           return decMoney;
        }

 

 

Advertisements