Unable to send null parameter to Sybase Stored Procedure using .Net ASE native ADO client

I'm having and error when I try to call a Sybase stored procedure provinding a null parameter.

I wrote a sandbox (see code bellow)

When I run the code, I get "Unsupported parameter type" exception. The only way the code works is by removing the null parameter (which defaults to null BTW), but this is not an option for me because the code is contained within a clutered ORM.

I'm ussing Sybase.AdoNet2.AseClient v 1.15.346.0. The sybase database version is 12.5.4 I'd be glad if you could help me. Thanks & Regards, Bernabé

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sybase.Data.AseClient;

namespace SybaseSPParamNulo
{
    class Program
    {
        static void Main(string[] args)
        {
            string cnxString = @"Data Source=192.168.0.8;Port=5000;Database=PiaSigna;Uid=sa;Pwd=123456;";
            Sybase.Data.AseClient.AseConnection cnx = new AseConnection(cnxString);
            AseCommand cmd = new AseCommand("sp_sectores_por_sucursal");
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            AseParameter p = new AseParameter("@suc", DBNull.Value );
            cmd.Parameters.Add(p);

            cnx.Open();
            cmd.Connection = cnx;
            cmd.ExecuteReader();
            cnx.Close();


        }
    }
} 


The following is the SP

CREATE procedure [dbo].[sp_sectores_por_sucursal]
@suc numeric(4)=NULL
AS 

select s.CODSEC,DESC_SEC from GYF_SECTORES s
join SUCURSAL_SECTORES ss on ss.CODSEC=s.CODSEC
where (NNSUCURSAL_ID=@suc)

IF @@ERROR <> 0 
   RETURN 1
RETURN 0

Answers


Yes it could be possible driver issue,try to set ansinull off after connecting.We have faced similar issue in delphi/sybase, i have resloved issued by using below code.

procedure TForm.TestConnectionAfterConnect(Sender: TObject);
begin
   TestConnection.ExecSQL('set ansinull off',[]);
end;

Need Your Help

How much PM I can send from popular Forum engines

forum phpbb vbulletin ipb invision-power-board

As u know there are many engines for forums (IP.Board, vBulletin, phpBB)