简体   繁体   English

无法通过 VBA 连接到 PostgreSQL 数据库

[英]Impossible to connect to PostgreSQL DB via VBA

I have a problem trying to connect to my local PGSQL db via VBA .我在尝试通过VBA连接到我的本地PGSQL数据库时遇到问题。 My code looks like this :我的代码如下所示:

Set conn = CreateObject("ADODB.Connection") strCnx = "Driver={PostgreSQL Unicode}; Server=127.0.0.1; Database=postgres; UID=postgres;Pwd=***;port=5432" conn.Open strCnx

The error I get is我得到的错误是

[Microsoft][ODBC Driver Controler]DATA SOURCE NAME NOT FOUND AND NO DEFAULT DRIVER SPECIFIED [Microsoft][ODBC 驱动程序控制器]未找到数据源名称且未指定默认驱动程序

I have tried a few things I found on stackoverflow , mainly installed the odbc drivers for postgresqlx64 , and tried to connect to the database using directly ODBC , which told me success when I tried to connect (picture below).我尝试了一些我在stackoverflow找到的东西,主要是为postgresqlx64安装了odbc驱动程序,并尝试直接使用ODBC连接到数据库,当我尝试连接时它告诉我成功(下图)。

Testing connection to PGSQL DB directly via ODBC直接通过 ODBC 测试与 PGSQL DB 的连接

But despite everything I tried, the error is the same when I try to execute my VBA code, and I'm out of ideas, so if there are any way you could help me, I would be most thankful :)但是,尽管我尝试了一切,但当我尝试执行 VBA 代码时,错误还是一样,而且我没有想法,所以如果有任何方法可以帮助我,我将不胜感激:)

Thanks谢谢

Frost

Make sure you install an ODBC driver with the same bitness as the application hosting your VBA.确保安装的 ODBC 驱动程序与托管 VBA 的应用程序具有相同的位数。 So 32-bits Excel means you need the 32-bits (x86) ODBC driver.所以 32 位 Excel 意味着您需要 32 位 (x86) ODBC 驱动程序。

If you install the proper ODBC driver, this error should go away.如果您安装了正确的 ODBC 驱动程序,此错误应该会消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM