9

I am trying to connect to Sybase database from .net core but I do not find any good library. Can someone suggest library to connect to Sybase?

1
  • No news from Sybase itself. You might have to check third party vendors.
    – Lex Li
    Apr 6, 2017 at 16:08

4 Answers 4

9

You have a couple of options of connecting to an ASE database in .net core:

  1. Set up an ODBC Data Source for your Sybase Database and use the System.Data.Odbc namespace/package on nuget. This package is currently in pre-release and targets .net core 2.0+.
    • If you can't upgrade to 2.0 or 2.1 then this option is not viable.
    • For a while I tried using this package, but had issues when it came to retrieving return values from procedure calls. Also the lack of support for named parameters was quite annoying.
  2. Use the AdoNetCore.AseClient namespace/package on nuget.
    • I started writing this due to my frustrations in using ODBC, and seeing no alternative
    • This is intended to support .net core 1.0, 1.1, 2.0 (and 2.1 when it is released), and framework 4.6. The reason for 4.6 support is so that it can be a drop-in replacement.
    • If you want to read the sources/documentation and figure out if it's the right fit for you, it's available on github.

At the end of the day, both packages implement their flavour of the ADO.NET interfaces (IDbConnection, IDbCommand, etc.), so the C# code to set them up will be fairly similar:

//System.Data.Odbc style
using(var connection = new OdbcConnection(...))
using(var commmand = connection.CreateCommand())
{
    connection.Open();
    //command stuff, note: named parameters unsupported
}

//AdoNetCore.AseClient style
using(var connection = new AseConnection(...))
using(var commmand = connection.CreateCommand())
{
    connection.Open();
    //command stuff
}
4
  • 1
    This should be the answer
    – Weihui Guo
    Feb 10, 2018 at 4:38
  • 1
    @Nicholas Sizer Thanks! How could I use AdoNetCore.AseClient with EF? Aug 15, 2018 at 10:54
  • 1
    @FelipeAugusto by implementing a compatible EF Data Provider Instructions on MSDN. Aug 15, 2018 at 23:54
  • does it still need to add the providerName="iAnywhere.Data.SQLAnywhere"?
    – Jeric Cruz
    Oct 8, 2020 at 9:04
6

I've used MSA.NetCore.ODBC with Dapper for my test .Net Core 2.0 project.

using System.Collections.Generic;
using System.Data;
using System.Data.Odbc;
using Dapper;

...
public IEnumerable<Book> GetBooks()
{
    using (IDbConnection dbConnection = new OdbcConnection("{your_db_connection}"))
    {
        IEnumerable<Book> books = dbConnection.Query<Book>("select * from books");

        return books;
    }
}
2
  • For some reason, the row count is correct (so obviously the connection is fine), but all the column returns null. Any idea?
    – Weihui Guo
    Feb 9, 2018 at 20:18
  • 4
    using MSA.NetCore.ODBC has no problem to connect to sybase, but somehow all the columns return by Dapper are null while row count is correct. I ended up using the System.Data.Odbc as answered below by Nicholas Sizer. Shouldn't up-vote this answer.
    – Weihui Guo
    Feb 10, 2018 at 4:35
0

There is a new SQL Anywhere driver for .NET Core. Support for EF Core is unfortunately still missing.

The following is the entry from SAP:

SQL Anywhere .NET Core Data Provider The SQL Anywhere Provider for .NET Core is an ADO.NET driver that provides data access from .NET Core applications to SAP SQL Anywhere databases.

The driver is Sap.Data.SQLAnywhere.Core.v2.1.dll and is available on Microsoft Windows. It is included in the SAP SAP IQ Database Client.

ADO.NET Support Most ADO.NET features are supported by the provider. The following ADO.NET functionality is not available for .NET Core:

  • Distributed transaction enlistment with a transaction coordinator
  • SACredential class
  • SAConnection( string connectionString,SACredential credential) method
  • SAPermission class
  • SAFactory.CreatePermission method
  • Entity Framework

https://help.sap.com/viewer/a894a54d84f21015b142ffe773888f8c/16.1.5.0/en-US/81e7c7253f0b42a0b8fb0f6f8a30de2d.html

1
  • At this time, the driver is only usable under Windows. According to SAP, compatibility with Linux will follow soon.
    – gutzi
    Mar 7, 2022 at 7:24
-1

Could you use the ODBC driver that comes with the Sybase client or Sybase SDK for Developers?

6
  • 1
    Could you please provide some example, How can we implement?
    – Mikayel
    Apr 12, 2017 at 15:57
  • I don't know .net core. If you know that .Net core can use ODBC, you could either install the Sybase client for Windows or the SDK for ASE developers (available on sap.com). Once installed on your Windows machine, you will open the "ODBC Data Source Administrator" on Windows to define your connection source to the Sybase ASE database. archive.sap.com/discussions/thread/3565945
    – Vince
    Apr 12, 2017 at 18:30
  • We need to run application on Linux server. Do you have any idea about ODBC in Linux server?
    – Mikayel
    Apr 13, 2017 at 10:45
  • 1
    Looks like it is possible to install the Sybase ODBC driver on Linux: dba.stackexchange.com/questions/162029/…
    – Vince
    Apr 13, 2017 at 12:45
  • 1
    We had a good crack with ODBC but couldn't figure out how to get return values out of our stored procedures. ODBC considered it a syntax error. In the end we wrote our own ADO.NET driver for .NET Core: github.com/DataAction/AdoNetCore.AseClient Jan 30, 2018 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.