centos – 无法使用ISQL连接到MS-SQL

StackExchange上的第一篇文章 – 请放心:)

我在Centos 6中设置了ODBC,以便从我的Asterisk安装中执行ms-SQL查询.

我的配置文件是:

/etc/odbc.ini

[asterisk-connector]
Description     = MS sql connection to 'asterisk' database
Driver          = /usr/lib64/libtdsodbc.so
Setup           = /usr/lib64/libtdsS.so
Servername      = sql2
Port            = 1433
Username        = MyUsername
Password        = MyPassword
TDS_Version     = 7.0

/etc/odbcinst.ini

[odbc-test]
Description = TDS connection
Driver = /usr/lib64/libtdsodbc.so
Setup = /usr/lib64/libtdsS.so
UsageCount = 1
FileUsage = 1

/etc/asterisk/res_odbc.conf

[asterisk-connector]
enabled => yes
dsn => asterisk-connector
username => MyUsername
password => MyPassword
pooling => no
limit =>
pre-connect => yes

当我传入密码和用户名时,我能够通过Isql连接:

[root@TestVM etc]# isql -v asterisk-connector MyUsername MyPassword
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
sql>

..但我应该能够连接没有用户名/密码.所有返回的是:

[root@TestVM etc]# isql -v asterisk-connector
[S1000][unixODBC][FreeTDS][sql Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][sql Server]Adaptive Server connection Failed
[Isql]ERROR: Could not sqlConnect

就好像Isql无法从配置文件中读取用户名和密码.

我需要能够在Asterisk拨号方案中执行MS-sql查找,但为了实现这一点,我必须能够仅使用数据源名称调用Isql,并且无法传递身份验证参数.

我在网上阅读的所有指南都说我应该能够连接到

isql -v asterisk-connector

命令,但这不适合我.

我已经把头发拉了几天,所以任何有关正确方向的帮助或指示都会非常感激.

提前致谢.

编辑:

我打开了日志记录,可能有一些线索.用户名和密码肯定没有传入.看:

[ODBC][27557][1455205133.129690][sqlConnect.c][3614]
                Entry:
                        Connection = 0xac3080
                        Server Name = [asterisk-connector][length = 18 (sql_NTS)]
                        User Name = [NULL]
                        Authentication = [NULL]
                UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'

                DIAG [01000] [FreeTDS][sql Server]Adaptive Server connection Failed

                DIAG [S1000] [FreeTDS][sql Server]Unable to connect to data source

所以这里的用户名和身份验证是[NULL].显然没有在odbc.ini或res_odbc.conf中获取用户名/密码,但问题是原因.我会继续调查:)

EDIT2:

Osql实用程序返回:

[root@TestVM etc]# osql -S sql2 -U MyUsername -P MyPassword
checking shared odbc libraries linked to isql for default directories...
strings: '': No such file
        trying /tmp/sqlH ... no
        trying /tmp/sqlL ... no
        trying /etc ... OK
checking odbc.ini files
        reading /root/.odbc.ini
[sql2] not found in /root/.odbc.ini
        reading /etc/odbc.ini
[sql2] found in /etc/odbc.ini
found this section:
looking for driver for DSN [sql2] in /etc/odbc.ini
  no driver mentioned for [sql2] in odbc.ini
looking for driver for DSN [default] in /etc/odbc.ini
osql: error: no driver found for [sql2] in odbc.ini

解决方法

我将在你的odbc.ini中用“UID”和“密码”替换“用户名”,从 FreeTDS Manual – Chapter 4 – Preparing ODBC开始:

The original ODBC solution to this conundrum employed the odbc.ini file. odbc.ini stored information about a server,kNown generically as a Data Source Name (DSN). ODBC applications connected to the server by calling the function sqlConnect(DSN,UID,PWD),where DSN is the Data Source Name entry in odbc.ini,UID is the username,and PWD the password. Any and all information about the DSN was kept in odbc.ini. And all was right with the world.

The ODBC 3.0 specification introduced a new function: sqlDriverConnect. The connection attributes are provided as a single argument,a string of concatenated name-value pairs. sqlDriverConnect subsumed the functionality of sqlConnect,in that the name-value pair string allowed the caller to pass — in addition the the original DSN,and PWD — any other parameters the driver Could accept. Moreover,the application can specify which driver to use. In effect,it became possible to specify the entire set of DSN properties as parameters to sqlDriverConnect,obviating the need for odbc.ini. This led to the use of the so-called DSN-less configuration,a setup with no odbc.ini.

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native