Skip to content

Instantly share code, notes, and snippets.

@alex-litvak
Created August 12, 2015 22:11
Show Gist options
  • Save alex-litvak/b44fb6e391697cd60e06 to your computer and use it in GitHub Desktop.
Save alex-litvak/b44fb6e391697cd60e06 to your computer and use it in GitHub Desktop.
.Net example (how to connect to Redshift)
using System;
using System.Data;
using System.Data.Odbc;
namespace your_namespace
{
class ConnectSample
{
public static void Main(string[] args)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
string server = "your_server.redshift.amazonaws.com";
string port = "your_port";
string userName = "user name";
string userPassword = "user password";
// Database name
string DBName = "your_database_name";
try
{
string connString = "Driver={Amazon Redshift (x64)};" +
String.Format("Server={0};Database={1};" +
"UID={2};PWD={3};Port={4};SSL=true;Sslmode=Require",
server, DBName, userName,
userPassword, port);
OdbcConnection conn = new OdbcConnection(connString);
conn.Open();
// try a query
conn.Close();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex.Message);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment