Created
August 12, 2015 22:11
-
-
Save alex-litvak/b44fb6e391697cd60e06 to your computer and use it in GitHub Desktop.
.Net example (how to connect to Redshift)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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