2

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
  • SP code looks correct - http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc32300_1251/html/sqlug/sqlug605.htm – Mike Gardner Nov 16 '13 at 04:07
  • Yes, as a matter of fact, if a execute the procedure from a client program like "ASE Server Client" I don't get any error. I forgot to mention that I found the same problem with parameterized queries. Could that be a problem of the client library I'm using? – Bernabé Panarello Nov 18 '13 at 11:46

1 Answers1

1

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;
SSE
  • 445
  • 2
  • 10
  • 29