MeanGreen
MeanGreen

Reputation: 3305

How can I connect with Sybase 17 ASA in .NET Core, using ODBC?

We have a Sybase 17 ASA server and want to connect using an ODBC driver. Our goal is to use the full .NET Core 2.1 and above, not .NET Standard or .NET Framework 4.x.

Upvotes: 3

Views: 3403

Answers (3)

RemarkLima
RemarkLima

Reputation: 12037

There is now a .NET Core 3.1 library iAnywhere.Data.SQLAnywhere.NETCore

https://www.nuget.org/packages/iAnywhere.Data.SQLAnywhere.NETCore/

So far, this has provided the results I've needed to query data and using native libraries rather than ODBC or the old 4.6 libraries.

Edit to add, I believe it is still Windows only, so doesn't open up Unix hosting sadly - but is a massive improvement to using the old .NET libraries.

Upvotes: 2

access_granted
access_granted

Reputation: 1907

Create a linked server to the IQ and do the simple: insert into remoteserver.database.dbo.table_name select * from dbo.table_name;

This is how data is often transfered between ASE and IQ anyway.

Upvotes: 0

MeanGreen
MeanGreen

Reputation: 3305

1. Prerequisites

Let's assume you've already installed SQL Anywhere 17 on the machine, including the required drivers.

2. Application setup

  • Create a new .NET Core application, Console will be used in this example. I've used version 2.2.
  • Add the NuGet package System.Data.Odbc

3. C# code

  • Add the following namespaces:

    using System.Data;
    using System.Data.Odbc;

  • Setup the connectionstring:

    DRIVER={SQL Anywhere 17};server=srv_name;Database=db_name; Uid=user;pwd=pass;LINKs=tcpip(host=aaa.bbb.ccc.ddd)

  • Retrieve some data to confirm it works:

    connection.Open();  
    var cmd = new OdbcCommand("select top 5 * from *table*", connection);  
    using (var reader = cmd.ExecuteReader())  
    {  
      while (reader.Read())    
      {    
        for (var i = 0; i < reader.FieldCount; i++)  
        {      
          Console.WriteLine(reader[i]);  
        }  
      }  
    }

Upvotes: 0

Related Questions