Monthly Archives: July 2014

Connecting to Remote Sybase SQL Anywhere from C#

I recently had to complete a small project that required connecting to a remote Sybase SQL Anywhere 11 instance using C#. The first challenge was to find the correct Sybase SQL Anywhere 11 ODBC connection string.

The result of Googling for “sql anywhere odbc connection string” gives several possibilities.

The one which worked, provided options for a default local engine or remote engine that is not running.   Even though neither applied, together with some colleague who deserve titles as local Sybase gurus, we were able to determine the following connection string:

Driver={SQL Anywhere 11};DatabaseName=my_db_name;EngineName=my_server_name;uid=username;pwd=password;LINKs=tcpip(host=host_ip_address)

After installing SQL Anywhere 11, and ensuring that there is a valid SQL Anywhere 11 ODBC driver as shown below


I was able to connect using the following C# code:

var connectionString = @"Driver={SQL Anywhere 11};DatabaseName=my_db_name;EngineName=my_server_name;uid=username;pwd=password;LINKs=tcpip(host=host_ip_address)";
 using (var cn = new OdbcConnection(connectionString))
 var cmd = new OdbcCommand("select * from dbo.users", cn);

 using (var reader = cmd.ExecuteReader())
 while (reader.Read())
    for (var i = 0; i < reader.FieldCount; i++)
      // option here is to read a name of the column


to query database and grab some objects from the table.