gpt4 book ai didi

vba - Azure PostgreSQL 的 SSL 连接字符串 - 正确的语法

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:27 41 4
gpt4 key购买 nike

我有一个连接到 PostgreSQL 数据库的 Microsoft Excel 工作簿。我在本地主机上使用数据库已有一段时间了。

我现在已将我的数据库移动到 Azure PostgreSQL。我已经成功地重新配置了我的查询/连接以将数据拉入电子表格(通过在“ODBC 数据源 64 位”中设置 DSN)并将 SSL 设置为要求。

工作簿包含一些 vba,用于将数据写回数据库。我收到错误:

Runtime error: '-2147467259 (80004005)': FATAL: SSL connection is required. Please specify SSL options and retry.

错误在 dbConnPublic.Open sqlConnString 行上抛出

代码的相关部分如下所示:

Sub WriteRowToDB()

' Define connectivity
Dim dbConnPublic As New ADODB.Connection
Dim sqlConnString As String

sqlConnString = OpenConnection()
dbConnPublic.Open sqlConnString

End Sub


Public Function OpenConnection() As String

'Define connection objects and terms
Dim sqlConnString As String

Dim myDriver As String: myDriver = "{PostgreSQL ANSI(x64)}"
Dim myServer As String: myServer = "djm-main-01.postgres.database.azure.com"

Dim myDatabase As String: myDatabase = "postgres"
Dim myUserName As String: myUserName = "djmmain01admin@djm-main-01"
Dim myPassword As String: myPassword = "[my password]" ' this replaced by the real password

' Open connection
sqlConnString = "Driver={PostgreSQL ANSI(x64)};" & _
"DSN=postgres;" & _
"Server=" & myServer & ";" & _
"Port=5432;" & _
"UID=" & myUserName & ";" & _
"PWD=" & myPassword & ";" & _
"Database=" & myDatabase & ";" & _




"ssl=true;READONLY=0;PROTOCOL=6.4;FAKEOIDINDEX=0;SHOWOIDCOLUMN=0;ROWVERSIONING=0;SHOWSYSTEMTABLES=1"

OpenConnection = sqlConnString

End Function

我已经尝试了 ssl=true、ssl=required、sslmode=required 的每一种组合,使用两个参数和三个参数,一些大写,一些小写,一些混合。找不到任何有区别的东西。也不确定这种语法是 Azure、PostgreSQL 还是 ADODB。

请注意,我还可以使用 DBeaver 和命令行 psql 从 Windows 使用 SSL 成功连接到 Azure 数据库。

最佳答案

大家好,正在观看的人。所以我解决了这个问题。

其实很简单,需要的参数是ssmode=require。它区分大小写。我一定是在我的排列中以某种方式错过了这一点。因此假设语法由 PostgreSQL ODBC 驱动程序确定。

此资源帮助: https://www.connectionstrings.com/

需要注意的其他陷阱:当密码包含在连接字符串中时,任何非字母数字都需要进行 url 编码,我没有想到,所以我的系统生成的密码必须带有感叹号转换为 %21。我从位于 HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ 的用户 DSN 获得了编码密码​​

但是我现在已经更改了密码,因此它不使用非字母数字。

希望这是有用的。

关于vba - Azure PostgreSQL 的 SSL 连接字符串 - 正确的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59516000/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com