代码之家  ›  专栏  ›  技术社区  ›  Digvijay Sawant

使用excel vba连接到红移

  •  0
  • Digvijay Sawant  · 技术社区  · 6 年前

    Private Sub CommandButton1_Click()
    
        Dim rs_opex As Worksheet
        Set rs_opex = ThisWorkbook.Sheets("OPEX")
    
        'Declare Variables
        Dim objMyconn As Object
        Dim objMyCmd As Object
        Dim objMyRecordset As Object
    
        Set objMyconn = CreateObject("ADODB.Connection")
        Set objMyCmd = CreateObject("ADODB.Command")
        Set objMyRecordset = CreateObject("ADODB.Recordset")
    
          objMyconn.ConnectionString = "DRIVER={PostgreSQL Unicode};" & _
                "SERVER=something;" & _
                "DATABASE=whatever;" & _
                "USER=sawantdr;" & _
                "PORT=1234;" & _
                "PASSWORD=abc1234;" & _
                "Option=0"
    
            objMyconn.Open
    
    
    End Sub
    

    我有个错误说 enter image description here

    我想可能是因为SSL关闭了。有没有办法在程序上打开SSL或者我做错了什么?如果需要更多信息,请告诉我。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Digvijay Sawant    6 年前

    经过数小时的尝试,我发现Redshift有自己的ODBC连接器。可以在这里找到: https://docs.aws.amazon.com/redshift/latest/mgmt/install-odbc-driver-windows.html . 代码如下:

    Dim oConn As Object
        Set oConn = CreateObject("ADODB.Connection")
        Dim cmd As Object
        Set cmd = CreateObject("ADODB.Command")
        ' Connection Parameters
        Dim strUsername As String
        Dim strPassword As String
        Dim strServerAddress As String
        Dim strDatabase As String
    
        ' User:
        strUsername = "***"
        ' Password:
        strPassword = "***"
        ' Server Address:
        strServerAddress = "***"
        ' Database
        strDatabase = "***"
    
         oConn.Open "Driver={Amazon Redshift (x86)};" & _
                "Server=" & strServerAddress & ";" & _
                "Port=***;" & _
                "Database=***;" & _
                "Uid=" & strUsername & ";" & _
                "Pwd=" & strPassword & ";"