【问题标题】:MAC OSX - How to solve "Could not SQLConnect" errorMAC OSX - 如何解决“无法 SQLConnect”错误
【发布时间】:2018-02-02 10:30:42
【问题描述】:

我正在尝试连接到我的 sql server 数据库,但它无法正常工作。

freetds 正在运行,查看命令:

tsql -S myserver.database.windows.net -U myuser -P mypassword

输出:

locale is "C/UTF-8/C/C/C/C"
locale charset is "UTF-8"
using default charset "UTF8"
1> 

但是当我尝试运行命令 isql 时,它返回错误。

命令:

isql -v MYSERVER myuser mypassword

输出:

[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

我的文件:

freetds.conf:

#   $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same 
# name is found in the installation directory.  
#
# For information about the layout of this file and its settings, 
# see the freetds.conf manpage "man freetds.conf".  

# Global settings are overridden by those in a database
# server specific section
[global]
    # TDS protocol version
    tds version = 8.0

    # Whether to write a TDSDUMP file for diagnostic purposes
    # (setting this to /tmp is insecure on a multi-user system)
;   dump file = /tmp/freetds.log
;   debug flags = 0xffff

    # Command and connection timeouts
;   timeout = 10
;   connect timeout = 10

    # If you get out-of-memory errors, it may mean that your client
    # is trying to allocate a huge buffer for a TEXT field.  
    # Try setting 'text size' to a more reasonable limit 
    text size = 64512

    # If you experience TLS handshake errors and are using openssl,
    # try adjusting the cipher list (don't surround in double or single quotes)
    # openssl ciphers = HIGH:!SSLv2:!aNULL:-DH

[MYSERVER]
   host = myserver.database.windows.net
   port = 1433
   tds version = 8.0
   client charset = UTF8

odbcinst.ini:

[FreeTDS]
Description = FreeTDS
Driver      = /usr/local/lib/libtdsodbc.so
Setup       = /usr/local/lib/libtdsodbc.so
UsageCount  = 1
Trace       = Yes
TraceFile   = /Users/giorgecaique/Documents/sql.log

odbc.ini:

[MYSERVER]
Description = MYSERVER
Driver      = FreeTDS
Database    = mydatabase
Server      = myserver.database.windows.net
UserName    = myuser
Password    = mypassword
TDS_Version = 8.0

谁能帮帮我?我已经看过很多关于如何解决这个问题的教程,但没有一个对我有用。

【问题讨论】:

    标签: sql-server database macos freetds unixodbc


    【解决方案1】:

    odbc.ini 文件中,您需要一个Servername 属性,它指向freetds.conf 中的DSN 名称。此外,8.0 不是有效版本(长篇大论,请参阅文档),它是 UTF-8 而不是 UTF8。例如:

    freetds.conf:

    [MYSERVER]
       host = myserver.database.windows.net
       port = 1433
       tds version = 7.1
       client charset = UTF-8
    

    然后在odbc.ini:

    [MYSERVER]
    Description = MYSERVER
    Driver      = FreeTDS
    Database    = mydatabase
    Servername  = MYSERVER
    UserName    = myuser
    Password    = mypassword
    TDS_Version = 7.1
    

    祝你好运!

    【讨论】:

    • 感谢您的回复,但仍然无法正常工作。 “Could not SQLConnect”错误仍然存​​在。
    【解决方案2】:

    您是否检查过您拥有库/usr/local/lib/libtdsodbc.so

    我遇到了类似的错误。我按照link 的本指南修复了我的错误。

    我相信您可能没有安装freetds 的驱动程序,您可以通过Homebrew 安装: $ brew install freetds --with-unixodbc

    【讨论】:

      【解决方案3】:

      您是否从这里尝试过 emehex 的回答:

      Can't open lib 'ODBC Driver 13 for SQL Server'? Sym linking issue?

      sudo ln -s /usr/local/etc/odbcinst.ini /etc/odbcinst.ini
      sudo ln -s /usr/local/etc/odbc.ini /etc/odbc.ini
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-20
        相关资源
        最近更新 更多