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?

Mikayel
  • 150
  • 1
  • 3
  • 8

4 Answers4

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
}
Nicholas Sizer
  • 3,490
  • 3
  • 26
  • 29
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;
    }
}
Ivan Shevtsiv
  • 311
  • 2
  • 10
  • 13
  • 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 09 '18 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 '18 at 04: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

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

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

Vince
  • 734
  • 1
  • 5
  • 10
  • 1
    Could you please provide some example, How can we implement? – Mikayel Apr 12 '17 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. https://archive.sap.com/discussions/thread/3565945 – Vince Apr 12 '17 at 18:30
  • We need to run application on Linux server. Do you have any idea about ODBC in Linux server? – Mikayel Apr 13 '17 at 10:45
  • 1
    Looks like it is possible to install the Sybase ODBC driver on Linux: https://dba.stackexchange.com/questions/162029/native-sybase-odbc-driver – Vince Apr 13 '17 at 12:45
  • For Sybase it is normal. Do you know any good library for ODBC in .net core? – Mikayel Apr 17 '17 at 12:51
  • 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: https://github.com/DataAction/AdoNetCore.AseClient – sheikhjabootie Jan 30 '18 at 06:37