如何找到连接字符串的 ODBC 驱动程序名称?

How to find the ODBC driver name for a connection string?

每当我使用带有完整连接字符串的 ODBC 驱动程序,而不仅仅是 DSN 条目时,我经常会收到类似于此的错误

Data source name not found and no default driver specified

我有正确的连接字符串语法(或者 Internet 上说的),但我怀疑我不知道我正在使用的当前版本的 ODBC 驱动程序的正确名称

如何找到 32 位或 64 位的正确名称?

使用 ODBC 数据源管理器应用程序。确保根据您的应用程序构建目标使用 32 位或 64 位版本。然后 select "File DSN" 选项卡

点击"Add"按钮,select您安装的驱动程序

然后点击"Advanced"按钮

然后您可以复制并粘贴正确的驱动程序名称,并取消 ODBC 数据源管理器应用程序

例如

DRIVER={PostgreSQL ODBC Driver(UNICODE)}

添加所需的其余参数,您将拥有适用于当前安装的驱动程序版本的有效 ODBC 连接字符串

例如

Driver={PostgreSQL ODBC Driver(UNICODE)};Server=ruru.nz;Port=5432;Database=TheInternet;Uid=tfd;Pwd=p455w0rd;

享受:-)

Get-OdbcDsn -Name "[dsn-name]" -DsnType "[system|user|file]" -Platform "64-bit"

你也可以使用powershell来获取它。并可能构建完整的连接字符串。

$dsn = Get-OdbcDsn -Name "dsn-plus" -DsnType "user" -Platform "64-bit"
$dsn
$dsn.DriverName
#$dsn.Attribute

$connecton_string = 'driver="' + $dsn.DriverName + '";'
foreach ($key in $dsn.Attribute.Keys) {
    if ([string]::IsNullOrWhiteSpace($dsn.Attribute[$key])) {
        $connecton_string = $connecton_string + $key + ";";
    } else {
        $connecton_string = $connecton_string + $key + "=" + $dsn.Attribute[$key] + ";";
    }
}

$connecton_string