9951 explained code solutions for 126 technologies


amazon-redshiftHow can I connect to Amazon Redshift using .NET?


You can connect to Amazon Redshift using .NET by using the Npgsql library. Npgsql is an open source .NET data provider for PostgreSQL. It supports all PostgreSQL features and is fully managed and supported by the PostgreSQL community.

To connect to Amazon Redshift using Npgsql, you need to add the Npgsql NuGet package to your project.

Install-Package Npgsql

Once the package is installed, you can create a connection string and use it to open a connection to the database.

string connString = "Server=myredshiftcluster.us-east-1.redshift.amazonaws.com;Port=5439;User Id=mymasteruser;Password=mypassword;Database=dev;";

using (NpgsqlConnection conn = new NpgsqlConnection(connString))
{
    conn.Open();
    // Execute commands
}

The code above will open a connection to the Amazon Redshift cluster using the provided connection string. Once the connection is open, you can execute commands against the database.

Helpful links

Edit this code on GitHub