Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 424
Mikayel Mikirtumov Avatar asked Apr 06 '17 16:04

Mikayel Mikirtumov


People also ask

How do I connect to a Sybase database?

Use the Connect to Sybase dialog box to connect to the Sybase Adaptive Server Enterprise (ASE) instance that you want to migrate. To access this dialog box, on the File menu, select Connect to Sybase. If you have previously connected, the command is Reconnect to Sybase.

How do I access Sybase database from Windows?

Start Sybase Central or Interactive SQL and open the Connect dialog (if it doesn't appear automatically). Open the Identification tab of the dialog, enter a user ID and a password. Click the Database tab of the dialog. Specify a file in the Database File field (including the full path, name, and extension).

How do I connect to Sybase ASE?

To connect to Sybase ASEOn the File menu, select Connect to Sybase. If you previously connected to Sybase, the command name will be Reconnect to Sybase. In the Provider box, select any of the installed providers on the machine to connect to Sybase server.


1 Answers

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
}
like image 192
Nicholas Sizer Avatar answered Sep 18 '22 16:09

Nicholas Sizer