Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS RedShift - .NET Core (ODBC Support?)

How can I connect and run queries against AWS RedShift using .NET Core? Code sample please. I have gone through the AWS docs and .Net Core docs but no luck.

like image 755
sk1900 Avatar asked Jan 31 '17 00:01

sk1900


People also ask

How do I connect to redshift with ODBC?

Amazon Redshift ODBC Driver (32-bit)Choose the System DSN tab to configure the driver for all users on the computer, or the User DSN tab to configure the driver for your user account only. Choose Add. The Create New Data Source window opens. Choose the Amazon Redshift ODBC driver, and then choose Finish.

What is Amazon Redshift ODBC?

The Amazon Redshift ODBC Driver is a powerful tool that allows you to connect with live Amazon Redshift data, directly from any applications that support ODBC connectivity. Read, write, and update Amazon Redshift data through a standard ODBC Driver interface.

What is redshift ODBC driver 64 bit?

More ODBC Drivers. Devart ODBC Driver for Amazon Redshift is a high-performance connectivity solution with enterprise-level features for accessing Amazon Redshift databases from ODBC-compliant reporting, analytics, BI, and ETL tools on both 32-bit and 64-bit Windows, macOS, and Linux.

What is the difference between JDBC and ODBC?

ODBC is a standard Microsoft Windows® interface that enables communication between database management systems and applications typically written in C or C++. JDBC is a standard interface that enables communication between database management systems and applications written in Oracle Java.


1 Answers

This answer is one for a particular point in time and won't age well...

The EntityFramework Core project is the one I'd keep the closest eye on. The lack of ODBC is well known, especially for those who want to connect to Oracle. For the time being, you may need to fork an Oracle client for .NET core and make modifications as necessary.

I found these projects after a quick Google search that may be able to help you for now...

- https://github.com/LinqDan/oracleclientcore - https://github.com/LinqDan/Mono.Data.OdbcCore

Longer term, you'll want to keep an eye on these two GitHub issues which are tracking it for EntityFramework Core and the .NETStandard APIs..

  • https://github.com/dotnet/corefx/issues/13035
  • https://github.com/aspnet/EntityFramework/issues/7432

Update 6/23/2017:

This is now possible through the Npgsql.EntityFrameworkCore.PostgreSQL NuGet package and associated Entity Framework Core packages. Apparently the PostgreSQL team was tired of waiting around for ODBC support (which still isn't available in the latest netstandard2.0 yet) and wrote their own driver using netstandard - back in the November timeframe. The getting started page on the npgsql website covers it's usage in the old JSON project format - but the dependencies listed are still valid.

Here is how you would use the package...

using (var conn = new NpgsqlConnection("Host=myserver;Username=mylogin;Password=******;Database=music"))
{
    conn.Open();
    using (var cmd = new NpgsqlCommand())
    {
        cmd.Connection = conn;

        cmd.CommandText = "SELECT name FROM artists";
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
                Console.WriteLine(reader.GetString(0));
            }
        }
    }
}

One thing to keep in mind when using this driver - it's written for PostgreSQL, not Redshift. While Redshift is based on PostgreSQL, it's underlying engine is much more like Cassandra than anything else. As a result, Amazon had to make some choices in the development to drop certain things that PostgreSQL does support - such as SQL variables. Because of this, you will have a fairly limiting experience for certain things that you might be used to in other Entity Framework implementations. As long as you stay with using the direct access *Connection, *Command, and DataReader classes and write your own SQL, you should be fine.

like image 90
William Holroyd Avatar answered Sep 23 '22 14:09

William Holroyd