This is a quick note on connection string syntax.
The Connection String should be placed in your app configuration files and excluded from version control. However: just basic PoC code inline, this is a successful connection string to AWS Redshift from C# .
Setup Instructions – Install Npgsql to Project:
Open Visual Studio
Create New Console App
Go to Tools –> NuGet Package Manager –> Package Manager Console.
From Package Manager Console:
PM> Install-Package Npgsql -Version 4.0.4
Sample Code for Connecting to Redshift and Viewing Records:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Npgsql; namespace tealiumETL { class Program { static void Main(string[] args) { var connString = "Host=myservername.tealiumiq.com;Port=5439;Username=myUserName;Password=myPassword;Database=myDatabaseName;SSL Mode=Prefer;Trust Server Certificate=true;ServerCompatibilityMode=Redshift;TcpKeepAlive=true"; using (var conn = new NpgsqlConnection(connString)) { conn.Open(); // Retrieve some rows using (var cmd = new NpgsqlCommand("select * FROM my_schema_name.events__all_events LIMIT 10 ", conn)) using (var reader = cmd.ExecuteReader()) while (reader.Read()) Console.WriteLine(reader.GetString(0)); } } } }
You must be logged in to post a comment.