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

Andres G. Aragoneses knocte at gmail.com
Sun Mar 29 23:44:22 UTC 2015


This seems to be the same bug as 
https://bugzilla.xamarin.com/show_bug.cgi?id=26546 which has been fixed 
recently in the master branch.

On 26/03/15 21:39, Jon Curry wrote:
> 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:
>
> createproc DoTest(@byte tinyint output)
>
> as
>
> set at 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.
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>




More information about the Mono-devel-list mailing list