zoukankan      html  css  js  c++  java
  • AWS Redshift 采坑记

    1.不要使用快速启动集群的方式建立,否则vpc是一个巨坑

    2.要配置对应的Role 并配置化 role arn

    3..net 连接类

    using Amazon.Redshift;
    using Amazon.Redshift.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Odbc;
    using System.Text;
    
    namespace eXconsole
    {
         public  class redshiftdb
        {
            public void TestConnectivityOnMasterNode(string clusterName)
            {
                using (IAmazonRedshift redshiftClient = new AmazonRedshiftClient())
                {
                    try
                    {
                        DataSet ds = new DataSet();
                        DataTable dt = new DataTable();
                        DescribeClustersRequest describeClustersRequest = new DescribeClustersRequest() { ClusterIdentifier = clusterName };
                        DescribeClustersResponse describeClustersResponse = redshiftClient.DescribeClustersAsync().GetAwaiter().GetResult();
                        Cluster firstMatch = describeClustersResponse.Clusters[0];
    
                        String mainDbName = firstMatch.DBName;
                        String endpointAddress = firstMatch.Endpoint.Address;
                        int endpointPort = firstMatch.Endpoint.Port;
                        string masterUsername = firstMatch.MasterUsername;
                        string password = "your master password";
    
    
                        string odbcConnectionString = string.Concat("Driver={PostgreSQL Unicode}; Server=", endpointAddress
                            , "; Database=", mainDbName, "; UID=", masterUsername, "; PWD=", password
                            , "; Port=", endpointPort);
                        string odbcConnectionDsn = "DSN=UrlsRedShiftDb";
                        string query = "SELECT datname FROM pg_database WHERE datistemplate = false;";
    
                        using (OdbcConnection conn = new OdbcConnection(odbcConnectionString))
                        {
                            try
                            {
                                conn.Open();
                                OdbcDataAdapter da = new OdbcDataAdapter(query, conn);
                                da.Fill(ds);
                                dt = ds.Tables[0];
                                foreach (DataRow row in dt.Rows)
                                {
                                    Console.WriteLine(row["datname"]);
                                }
    
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Exception caught while communicating with RedShift master node: ");
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                    catch (AmazonRedshiftException e)
                    {
                        Console.WriteLine("Postgresql command execution on master node has failed.");
                        Console.WriteLine("Amazon error code: {0}",
                            string.IsNullOrEmpty(e.ErrorCode) ? "None" : e.ErrorCode);
                        Console.WriteLine("Exception message: {0}", e.Message);
                    }
                }
            }
        }
    }
  • 相关阅读:
    Kinect 开发 —— 硬件设备解剖
    Kinect 开发 —— 引言
    (转)OpenCV 基本知识框架
    OpenCV —— 摄像机模型与标定
    OpenCV —— 跟踪与运动
    OpenCV —— 图像局部与分割(二)
    OpenCV —— 图像局部与部分分割(一)
    OpenCV —— 轮廓
    OpenCV —— 直方图与匹配
    OpenCV —— 图像变换
  • 原文地址:https://www.cnblogs.com/Johnson-zhao/p/10758126.html
Copyright © 2011-2022 走看看