Skip to content

Repository files navigation

icon AdoNetCore.AseClient

A .NET Core DB Provider for SAP ASE

CodeFactorJoin the chat at https://gitter.im/DataAction/AdoNetCore.AseClient

Packages available at NuGet:

NameVersion
AdoNetCore.AseClient (Recommended)AdoNetCore.AseClient@NuGet
AdoNetCore.AseClient.StrongName (Strongly Named)AdoNetCore.AseClient.StrongName@NuGet

SAP (formerly Sybase) has supported accessing the ASE database management system from ADO.NET for many years. Unfortunately SAP has not yet made a driver available to support .NET Core, so this project enables product teams that are dependent upon ASE to keep moving their application stack forwards.

The current .NET 4 version of SAP's Sybase.Data.AseClient driver is a .NET Framework managed wrapper around SAP's unmanged ADO DB provider and is dependent upon COM. COM is a Windows-only technology and will never be available to .NET Core, making it difficult to port the existing SAP driver.

Under the hood, ASE (and Microsoft Sql Server for that matter) relies on an application-layer protocol called Tabular Data Stream to transfer data between the database server and the client application. ASE uses TDS 5.0.

This project provides a .NET Core native implementation of the TDS 5.0 protocol via an ADO.NET DB Provider, making SAP ASE accessible from .NET Core applications hosted on Windows, Linux, Docker and also serverless platforms like AWS Lambda.

Table of Contents

Downloads

The latest stable release of the AdoNetCore.AseClient is available on NuGet.

Objectives

  • Functional parity with the Sybase.Data.AseClient provided by SAP. Ideally, our driver will be a drop in replacement for the Sybase.Data.AseClient (with some namespace changes). The following types are supported:

    • AseClientFactory - .NET Core 2.1+
    • AseCommand
    • AseCommandBuilder
    • AseConnection
    • AseConnectionPool
    • AseConnectionPoolManager
    • AseDataAdapter
    • AseDataReader
    • AseDbType
    • AseDecimal
    • AseError
    • AseErrorCollection
    • AseException
    • AseInfoMessageEventArgs
    • AseInfoMessageEventHandler
    • AseParameter
    • AseParameterCollection
    • AseRowUpdatedEventArgs - .NET Core 2.0+
    • AseRowUpdatedEventHandler - .NET Core 2.0+
    • AseRowUpdatingEventArgs - .NET Core 2.0+
    • AseRowUpdatingEventHandler - .NET Core 2.0+
    • TraceEnterEventHandler
    • TraceExitEventHandler
  • Not all features are currently supported, and some features will not be supported. Refer to Unsupported features.

  • Performance equivalent to or better than that of Sybase.Data.AseClient provided by SAP. This is possible as we are eliminating the COM and OLE DB layers from this driver and .NET Core is fast.

  • Target all versions of .NET Core (1.0, 1.1, 2.0, 2.1 and 2.2)

  • Should work with Dapper at least as well as the Sybase.Data.AseClient

Performance benchmarks

Test methodology

To help adopt the AdoNetCore.AseClient, we have benchmarked it against the Sybase.Data.AseClient. See the wiki for how to run the benchmarks yourself.

We have benchmarked the AdoNetCore.AseClient against the Sybase.Data.AseClient in the following ways:

Single read, without pooling

Open a connection (unpooled) and invoke AseCommand.ExecuteReader(...) once and read back one row of data.

Single read, with pooling

Open a connection (pooled) and invoke AseCommand.ExecuteReader(...) once and read back one row of data.

Multiple reads, without pooling

Open a connection (unpooled) and invoke AseCommand.ExecuteReader(...) once and read back 12 rows of data.

Multiple reads, with pooling

Open a connection (pooled) and invoke AseCommand.ExecuteReader(...) once and read back 12 rows of data.

Multiple reads, multiple times, without pooling

Open a connection (unpooled) and invoke AseCommand.ExecuteReader(...) 9 times, and read back 11-12 rows of data each time.

Multiple reads, multiple times, with pooling

Open a connection (pooled) and invoke AseCommand.ExecuteReader(...) 9 times, and read back 11-12 rows of data each time.

Multiple reads, multiple writes, without pooling

Open a connection (unpooled) and invoke AseCommand.ExecuteReader(...) once, reading back 56 rows of data. Prepare a new AseCommand and invoke AseCommand.ExecuteNonQuery(...) for each of the 56 rows to update the database.

Multiple reads, multiple writes, with pooling

Open a connection (pooled) and invoke AseCommand.ExecuteReader(...) once, reading back 56 rows of data. Prepare a new AseCommand and invoke AseCommand.ExecuteNonQuery(...) for each of the 56 rows to update the database.

We perform these tests for .NET Core 1.1, .NET Core 2.0, and .NET Standard 4.6 using the AdoNetCore.AseClient. For comparison, we also perform these tests on .NET Standard 4.6 using the Sybase.Data.AseClient from SAP.

Environment

The goal of the benchmarking is not to establish the absolute performance of the driver or the ASE Server, but to show its equivalence as a substitute. As such, the test client and database server have been held constant in all tests.

Server:

Adaptive Server Enterprise/16.0 SP03 PL02/EBF 27413 SMP/P/AMD64/Windows 2008 R2 SP1/ase160sp03pl02x/0/64-bit/FBO/Fri Oct 06 14:34:03 2017

Client:

BenchmarkDotNet=v0.10.11, OS=Windows 10 Redstone 2 [1703, Creators Update] (10.0.15063.726) Processor=Intel Core i7-6700 CPU 3.40GHz (Skylake), ProcessorCount=8 Frequency=3328123 Hz, Resolution=300.4697 ns, Timer=TSC .NET Core SDK=2.1.3 [Host] : .NET Core 2.0.4 (Framework 4.6.25921.01), 64bit RyuJIT DefaultJob : .NET Core 2.0.4 (Framework 4.6.25921.01), 64bit RyuJIT

Test results

In all of the test cases the AdoNetCore.AseClient performed better or equivalent to the Sybase.Data.AseClient.

AdoNetCore.AseClient vs Sybase.Data.AseClient

Connection strings

connectionstrings.com lists the following connection string properties for the ASE ADO.NET Data Provider. In keeping with our objective of being a drop-in replacement for the Sybase.Data.AseClient, we aim to use identical connection string syntax to the Sybase.Data.AseClient, however our support for the various properties will be limited. Our support is as follows:

PropertySupportNotes
AnsiNullBy default (0) AnsiNull is disabled which means that SQL statements can use = NULL and IS NULL syntax. Set to 1 to instruct the connection to only permit IS NULL syntax.
ApplicationName or Application Name
BufferCacheSizeBuffer caching is automatically managed via an internal ArrayPool. Setting this value in the connection string does nothing, but the behaviour is supported.
CharsetIf not specified, the server should dictate the character set
ClientHostName
ClientHostProc
CodePageTypeThis doesn't appear to be relevant any more. You can specify the Charset without reference to a code page type, or allow the server to set the Charset which is the default behaviour.
Connection Lifetime or ConnectionLifetime
ConnectionIdleTimeout or Connection IdleTimeout or Connection Idle Timeout
CumulativeRecordCountTODO
Database or Db or Initial Catalog
Data Source or DataSource or Address or Addr or Network Address or Server Name
DSURL or Directory Service URLMultiple URLs are not supported; network drivers other than NLWNSCK (TCP/IP socket) are not supported; LDAP is not supported
EnableServerPacketSize
EncryptionThe designated encryption. Possible values: ssl, none.
EncryptPasswordValues 0 (disabled) and 1 (enabled) are supported. The highest encryption standard of the ASE 15.x and 16x servers is implemented.
LoginTimeOut or Connect Timeout or Connection TimeoutFor pooled connections this translates to the time it takes to reserve a connection from the pool
Max Pool Size
Min Pool Size
  • The pool will attempt to prime itself on creation up to this size (in a thread)
  • When a connection is killed, the pool will attempt to replace it if the pool size is less than Min
NamedParameters
PacketSize or Packet SizeThe server can decide to change this value
Ping Server
Pooling
Port or Server Port
Pwd or Password
TextSize
TrustedFileThis property must be used along with Encryption=ssl. The value must be set to the path to the trusted file.
Uid or UserID or User ID or User
UseAseDecimal

Supported types

Types supported when sending requests to the database

DbTypeSend.NET Type(s)Notes
AnsiStringstring
AnsiStringFixedLengthstring
Binarybyte[]
Booleanbool
Bytebyte
CurrencydecimalSent as decimal type; may change to send as TDS_MONEY, which is shorter
DateDateTimeTime component is ignored
DateTimeDateTime
DateTime2XASE does not support a DateTime2 type. Use DateTime instead
DateTimeOffsetXASE does not support a DateTimeOffset type. Use DateTime instead
Decimaldecimal
Doubledouble
GuidSystem.GuidTechnically ASE does not support GUID or UUID types. Our driver supports it, but converts to Binary under the hood. You can obtain the same result by calling .ToByteArray() and using DbType.Binary.
Int16short
Int32int
Int64long
ObjectXASE does not support an Object type
SBytesbyteSent as int16
Singlefloat
StringstringUTF-16 encoded, sent to server as binary with usertype 35
StringFixedLengthstringUTF-16 encoded, sent to server as binary with usertype 34
TimeTimeSpan
UInt16ushort
UInt32uint
UInt64ulong
VarNumericdecimal
XmlXASE does not support an Xml type

Types supported when reading responses from the database

ASE TypeReceive.NET Type(s)Notes
bigdatetimeXDateTimeTo be implemented. TDS_BIGDATETIME = 0xBB
bigintlong
bigtimeXDateTimeTo be implemented. TDS_BIGTIME = 0xBC
binarybyte[]
bitbool
charstring
dateDateTime
datetimeDateTime
decimaldecimal
double precisiondouble
floatfloat
imagebyte[]
intint
moneydecimal
ncharstring
numericdecimal
nvarcharstring
smalldatetimeDateTime
smallintshort
smallmoneydecimal
timeDateTimeWe have added a GetTimeSpan method to AseDataReader
tinyintbyte
unicharstringServer sends as binary with usertype 34
univarcharstringServer sends as binary with usertype 35
unsigned bigintulong
unsigned intuint
unsigned smallintusmallint
varcharstring
textstring
unitextstring
varbinarybyte[]

Code samples

Open a database connection

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();// use the connection...}

Execute a SQL statement and read response data

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();using(varcommand=connection.CreateCommand()){command.CommandText="SELECT FirstName, LastName FROM Customer";using(varreader=command.ExecuteReader()){// Get the results.while(reader.Read()){varfirstName=reader.GetString(0);varlastName=reader.GetString(1);// Do something with the data...}}}}

Execute a SQL statement that returns no results

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();using(varcommand=connection.CreateCommand()){command.CommandText="INSERT INTO Customer (FirstName, LastName) VALUES ('Fred', 'Flintstone')";varrecordsModified=command.ExecuteNonQuery();}}

Execute a SQL statement that returns a scalar value

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();using(varcommand=connection.CreateCommand()){command.CommandText="SELECT COUNT(*) FROM Customer";varresult=command.ExecuteScalar();}}

Use input parameters with a SQL query

Note: ASE only allows Output, InputOutput, and ReturnValue parameters with stored procedures

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString){connection.Open();using(varcommand= connection.CreateCommand()){command.CommandText="SELECT TOP 1 FirstName FROM Customer WHERE LastName = @lastName";command.Parameters.AddWithValue("@lastName","Rubble");varresult=command.ExecuteScalar();}}

Execute a stored procedure and read response data

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString){connection.Open();using(varcommand= connection.CreateCommand()){command.CommandText="GetCustomer";command.CommandType=CommandType.StoredProcedure;command.Parameters.AddWithValue("@lastName","Rubble");using(varreader=command.ExecuteReader()){// Get the results.while(reader.Read()){varfirstName=reader.GetString(0);varlastName=reader.GetString(1);// Do something with the data...}}}}

Execute a stored procedure that returns no results

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();using(varcommand=connection.CreateCommand()){command.CommandText="CreateCustomer";command.CommandType=CommandType.StoredProcedure;command.Parameters.AddWithValue("@firstName","Fred");command.Parameters.AddWithValue("@lastName","Flintstone");command.ExecuteNonQuery();}}

Execute a stored procedure that returns a scalar value

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();using(varcommand=connection.CreateCommand()){command.CommandText="CountCustomer";command.CommandType=CommandType.StoredProcedure;varresult=command.ExecuteScalar();}}

Use input, output, and return parameters with a stored procedure

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();using(varcommand=connection.CreateCommand()){command.CommandText="GetCustomerFirstName";command.CommandType=CommandType.StoredProcedure;command.Parameters.AddWithValue("@lastName","Rubble");varoutputParameter=command.Parameters.Add("@firstName",AseDbType.VarChar);outputParameter.Direction=ParameterDirection.Output;varreturnParameter=command.Parameters.Add("@returnValue",AseDbType.Integer);returnParameter.Direction=ParameterDirection.ReturnValue;command.ExecuteNonQuery();//Do something with outputParameter.Value and returnParameter.Value...}}

Execute a stored procedure and read response data with Dapper

varconnectionString="Data Source=myASEserver;Port=5000;Database=myDataBase;Uid=myUsername;Pwd=myPassword;";using(varconnection=newAseConnection(connectionString)){connection.Open();varbarneyRubble=connection.Query<Customer>("GetCustomer",new{lastName="Rubble"},commandType:CommandType.StoredProcedure).First();// Do something with the result...}

About

AdoNetCore.AseClient - a .NET Core DB Provider for SAP ASE

Topics

Resources

Stars

111 stars

Watchers

17 watching

Forks

Releases

Packages

Used by

Contributors

Languages