【问题标题】:odbcinst: SQLGetPrivateProfileString failed with Unable to find component nameodbcinst:SQLGetPrivateProfileString 失败,无法找到组件名称
【发布时间】:2017-11-13 15:44:59
【问题描述】:

我的默认用户可以毫无问题地使用 unixodbc。但是当我切换到另一个用户时,我得到一个错误。

[centos@ ~]$ odbcinst -q -s
[ODBC]
[Amazon Redshift DSN 32]

[centos@ ~]$ su ruser
Password:
[ruser@ centos]$ odbcinst -q -s
odbcinst: SQLGetPrivateProfileString failed with Unable to find component name.

在两个用户中都设置了环境变量:

AMAZONREDSHIFTODBCINI=/etc/amazon.redshiftodbc.ini
ODBCSYSINI=/usr/local/odbc
ODBCINI=/etc/odbc.ini
LD_LIBRARY_PATH=/usr/local/lib
LD_PRELOAD=/usr/local/lib/libodbcinst.so

odbc配置如下:

[ruser@ centos]$ odbcinst -j
unixODBC 2.3.4
DRIVERS............: /usr/local/odbc /odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/odbc /odbc.ini
FILE DATA SOURCES..: /usr/local/odbc /ODBCDataSources
USER DATA SOURCES..: /etc/odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

顺便说一句,我不明白为什么上面的路径中有空格。我不知道是否有办法改变它们。有什么想法可以解决这个问题吗?两个用户的整体 odbc 配置似乎相同。

【问题讨论】:

    标签: odbc unixodbc


    【解决方案1】:

    我在 Centos 上发现了完全相同的问题,我可以使用默认的 centos 用户进行连接,但不能使用任何其他用户。

    我能够通过将工作用户(或系统)odbc.iniodbcinst.ini 文件复制到另一个用户的主目录中来解决问题,就像这样(我已将它们重命名为 .odbc.ini.odbcinst.ini):

    ~/.odbc.ini

    [MSSQLTest]
    Driver = ODBC Driver 17 for SQL Server
    Server = tcp:<ip of server>
    

    ~/.odbcinst.ini

    [ODBC Driver 17 for SQL Server]
    Description=Microsoft ODBC Driver 17 for SQL Server
    Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.2.so.0.1
    UsageCount=1
    

    最后,我只需在我的~/.bashrc 文件中设置以下environment variables,就可以连接了。

    export ODBCSYSINI="<full path to user folder, which would be the evaluated path of {echo ~}>"
    export ODBCINSTINI=".odbcinst.ini"
    export ODBCINI="<full path to user folder, which would be the evaluated path of {echo ~}>/.odbc.ini"
    

    由于某种原因,我无法使用~ 来引用用户文件夹,所以我不得不在环境变量中手动指定完整的用户路径,因此我的完整.bashrc 文件很简单:

    export ODBCSYSINI="/home/mitch"
    export ODBCINSTINI=".odbcinst.ini"
    export ODBCINI="/home/mitch/.odbc.ini"
    

    通过此设置,我现在可以运行以下命令并成功连接:

    $ isql -v MSSQLTest <sql server username> <sql server password>
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> 
    

    【讨论】:

    • 嗨@mitchdav。非常感谢您的回复。不幸的是,我无法测试它,因为我不再在那家公司工作了:) 我什至因为提出这个问题而获得了Tumbleweed 徽章,所以我感谢你的回答和努力。
    猜你喜欢
    • 1970-01-01
    • 2017-08-20
    • 2017-03-08
    • 2019-04-22
    • 2016-06-10
    • 1970-01-01
    • 2022-12-20
    • 2018-06-08
    • 1970-01-01
    相关资源
    最近更新 更多