3

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.

MeanGreen
  • 3,098
  • 5
  • 37
  • 63

3 Answers3

2

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.

RemarkLima
  • 11,639
  • 7
  • 37
  • 56
0

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]);  
        }  
      }  
    }
MeanGreen
  • 3,098
  • 5
  • 37
  • 63
  • I need to connect to a Sybase server (IQ) in a .Net application. I don't have SQL Anywhere installed on my local PC. What are the options? – ca9163d9 Mar 06 '20 at 22:59
  • @ca9163d9 I have no idea. My advice is to create a separate question and hopefully somebody can answer it. :) – MeanGreen Mar 09 '20 at 07:01
0

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.

access_granted
  • 1,807
  • 20
  • 25