You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku最新栈Rails7应用部署tiny_tds/freetds的解决方案求助

在Heroku最新栈的Rails 7应用中安装tiny_tds并连接Azure MSSQL的问题

问题背景

需在Heroku最新栈的Rails 7应用中安装tiny_tds,用于部署Azure MSSQL插件。已成功安装buildpack,但通过Heroku Rails控制台执行以下连接代码时始终超时,本地执行则完全正常:

client = TinyTds::Client.new host: '<host>.database.windows.net', database: "<database>",username: "<username>@<host>.database.windows.net",password: "<password>", port: 1433, azure: true, tds_version: 7.4, timeout: 300, login_timeout: 300

报错信息:

Adaptive Server connection timed out ([server].database.windows.net:1433)

网络连通性测试

在Heroku bash中执行nslookup和nc测试,均显示网络连通正常:

nslookup测试输出

~ $ nslookup
> <host>.database.windows.net
Server:     <server ip address>
Address:    <server ip address>#53
Non-authoritative answer:
<host>.database.windows.net canonical name = <other host name>.eastus.database.windows.net.
<other host name>.eastus.database.windows.net   canonical name = <other host name>.trafficmanager.net.
<other host name>.trafficmanager.net    canonical name = <another host name>.control.database.windows.net.
Name:   <another host name>.control.database.windows.net
Address: <ip address>

nc测试输出

~ $ nc -zv <host>.database.windows.net 1433
Connection to <host>.database.windows.net (<ip address>) 1433 port [tcp/ms-sql-s] succeeded!

FreeTDS连接问题

推测是freetds与Heroku或buildpack的交互问题,已尝试多个版本的freetds buildpack。本地MacBook上执行freetds的tsql命令可快速连接多个MSSQL数据库,但在Heroku bash中执行相同命令超时:

~ $ tsql -H ***.rds.amazonaws.com -p 1433 -U *** -P ***
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
103Error 20002 (severity 9):
    Adaptive Server connection failed
Error 20002 (severity 9):
    Adaptive Server connection failed
There was a problem connecting to the server

FreeTDS版本配置对比

本地与Heroku的FreeTDS版本均为v1.3.13,仅在安装Heroku buildpack时设置了TDS_VERSION为7.3,无其他特殊配置:

本地配置

# LOCAL:
$ tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.3.13
             freetds.conf directory: /opt/homebrew/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.3
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes
                            OpenSSL: yes
                             GnuTLS: no
                               MARS: yes

Heroku配置

# Heroku:
$ heroku run bash -a <app>
Running bash on ⬢ <app>... up, run.4557 (Hobby)
~ $ tsql -C
Compile-time settings (established with the "configure" script)
                            Version: freetds v1.3.13
             freetds.conf directory: /app/freetds/etc
     MS db-lib source compatibility: no
        Sybase binary compatibility: no
                      Thread safety: yes
                      iconv library: yes
                        TDS version: 7.3
                              iODBC: no
                           unixodbc: no
              SSPI "trusted" logins: no
                           Kerberos: no
                            OpenSSL: yes
                             GnuTLS: no
                               MARS: yes

请求解决思路

内容的提问来源于stack exchange,提问作者Julie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 21:35:23