Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SYBASE ODBC .Net CORE

1. Has anyone successfully used ODBC from c# to Sybase ASE?
2. Or Better, has anyone successfully used Sybase ASE with .NET Core?

I am using .NET Core 1.1 and the current Sybase.AdoNet4.AseClient.dll doesn't work, so I am attempting to use ODBC. I have tried to use two ODBC packages:

  • Mono.Data.OdbcCore (NuGet)
  • MSA.Net.Core.ODBC (NuGet)

Both work well with in-line queries and both work well calling a Sybase Store Procedures WITHOUT Parameter but both have the same exact error when trying to send parameters to a sp, where the parameters are required.

Here is a snippet:

command.CommandType = CommandType.StoredProcedure;
command.CommandText = "XX_GetLookUp";
command.Parameters.Add("@Type", OdbcType.VarChar).Value = "ACC";
using (var reader = command.ExecuteReader()) {
    ...
}

I constantly receiving the following error during the command.ExecuteReader(): System.Data.Odbc.OdbcException: 'ERROR [ZZZZZ] [SAP][ASE ODBC Driver][Adaptive Server Enterprise]Procedure iKYC_GetLookUp expects parameter @Type, which was not supplied.

I have tried to use Type with and without the @ but each generate the same error.

I did try several other flavors as well:

  • command.CommandText = "{call dbo.iKYC_GetLookUp(?)}";
  • command.CommandText = "{call dbo.iKYC_GetLookUp}";
  • command.CommandText = "{dbo.iKYC_GetLookUp(?)}";
  • command.CommandText = "dbo.iKYC_GetLookUp(?)";
  • command.CommandText = "dbo.iKYC_GetLookUp ?";

Where each above generates: System.Runtime.InteropServices.SEHException: 'External component has thrown an exception.'

I also tried to build the parameter object separate, with no luck (same error, missing @Type):

OdbcParameter p = new OdbcParameter();
p.ParameterName = "@Type";
p.DbType = DbType.AnsiString;
p.Direction = ParameterDirection.InputOutput;
p.Value = "ACC";
cmd.Parameters.Add(p);

As stated prior, if I make the parameter as null, on the store procedure, the code works and data is returned as expected, so the issue appears to be around the parameters being passed.

Has anyone successfully used ODBC from c# to Sybase ASE? Has anyone successfully used Sybase ASE with .NET Core?

Additional information: I am using Visual Studio 2017 (v 15.2). Core 1.1 and using Sybase ASE 16.0 sp2.

like image 558
Monkey Man Avatar asked Jul 27 '17 00:07

Monkey Man


1 Answers

We had a similar issue - we wanted to use ADO.NET on the AWS Serverless stack - which is .NET Core only. We raised an issue with SAP requesting support for .NET Core, but got nothing back.

We had a go with ODBC and couldn't get it to work with return values on our stored procedures, and bit the bullet and wrote our own ADO.NET Core DbProvider for ASE 15-16.

It implements the TDS 5 protocol under the hood natively in .NET Core and outperforms the SAP/Sybase implementation in all of our test cases.

https://github.com/DataAction/AdoNetCore.AseClient

There's docs on the wiki to run the unit, integration and benchmark tests for yourself.

Most features are implemented, and pull requests and feedback are welcome. .NET 4.6 and .NET Core 1.0, 1.1, 2.0 and 2.1 are supported.

We have this working using AWS Lambda and .NET Core 2.0.

like image 188
sheikhjabootie Avatar answered Oct 20 '22 02:10

sheikhjabootie