[Mono-dev] TDS exception using DBNull.Value in SQL integer parameters

Jon Curry Jon.Curry at infor.com
Thu Mar 26 20:39:21 UTC 2015


My first post...so here goes.

I am attempting to port a large enterprise application to mono, and have been pleasantly surprised at how well most things work.

I am hitting one snag executing a SqlCommand that includes a SqlParameter whose data type is SqlDbType.TinyInt (have also tried Int), and whose value is DBNull.Value.

I just installed the latest monodevelop last Friday (v5.7).  Any fix or workaround would be appreciated!

:::Repro C# code:

      private static void SqlTest()
      {
         using ( var con = new SqlConnection( "Application Name=MyApp;Data Source=machinename;Database=MGLatest_Mono;User ID=sa;Pwd=xxx;MultipleActiveResultSets=True" ) )
         {
            con.Open();

            using ( var cmd = con.CreateCommand() )
            {
               cmd.CommandType = System.Data.CommandType.StoredProcedure;
               cmd.CommandText = "DoTest";
               cmd.Parameters.Add( new SqlParameter( "@byte", System.Data.SqlDbType.TinyInt ) );
               cmd.Parameters[ "@byte" ].Direction = System.Data.ParameterDirection.Output;
               // cmd.Parameters[ "@byte" ].Value = (byte)0;  // THIS WORKS
               cmd.Parameters[ "@byte" ].Value = DBNull.Value;  // THIS FAILS (as does null, or omitting)
               cmd.ExecuteNonQuery();
               Console.WriteLine( cmd.Parameters[ "@byte" ].Value );
            }
         }
      }

:::Repro Store Proc:

create proc DoTest(@byte tinyint output)
as
set @byte = 238

:::Exception:
Unhandled Exception:
System.Data.SqlClient.SqlException: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 ("@byte"): Data type 0x26 has an invalid data length or metadata length.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20150326/860d58e8/attachment.html>


More information about the Mono-devel-list mailing list