asp.net-core.net-coresybasesap-ase

How to connect to Sybase database from .net core


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?


Solution

  • 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
    }