EasyManuals Logo

Amazon Redshift User Manual

Amazon Redshift
131 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #115 background imageLoading...
Page #115 background image
Example : Connect to a Cluster by Using .NET
The following example connects to a cluster and runs a sample query that returns system tables. It does
not show server authentication. It is not necessary to have data in your database to use this example.
This example uses Npgsql, a .NET data provider for PostgreSQL.
using System;
using System.Data;
using Npgsql; // http://npgsql.projects.pgfoundry.org/
namespace redshift.amazon.com.docsamples
{
class ConnectToClusterExample
{
public static void Main(string[] args)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
//Server, e.g. "examplecluster.xyz.us-east-1.redshift.amazonaws.com"
String Server = "***provide server name part of connection
string****";
//Port, e.g. "5439"
String Port = "***provide port***";
//MasterUserName, e.g. "'masteruser'". Note use of single quotes.
String MasterUsername = "***provide master user name***";
//MasterUserPassword, e.g. "'mypassword'". Note use of single
quotes.
String MasterUserPassword = "***provide master user password***";
//DBName, e.g. "dev"
String DBName = "***provide name of database***";
String query = "select * from information_schema.tables;";
try
{
// Create a PostgeSQL connection string.
string connstring = String.Format(
"Server={0};Database={1};" +
"UID={2};PWD={3};Port={4};SSL=true;Sslmode=Require",
Server, DBName, MasterUsername,
MasterUserPassword, Port);
// Make a connection using the Npgsql provider.
NpgsqlConnection conn = new NpgsqlConnection(connstring);
conn.Open();
// Try a simple query.
string sql = query;
NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
API Version 2012-12-01
111
Amazon Redshift Management Guide
Connecting to a Cluster by Using .NET

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Amazon Redshift and is the answer not in the manual?

Amazon Redshift Specifications

General IconGeneral
ProviderAmazon Web Services (AWS)
Query LanguageSQL
Data StorageColumnar storage
SecurityEncryption at rest and in transit, VPC, IAM
BackupAutomated and manual snapshots
DeploymentCloud-based
TypeCloud-based data warehouse service
Primary UseData warehousing, analytics
IntegrationIntegrates with AWS services, BI tools, and ETL tools
Pricing ModelOn-demand and reserved instance pricing
Data CompressionColumnar storage with data compression
Performance OptimizationQuery optimization

Related product manuals