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 中获取用户名/密码,但问题是为什么。我会继续调查的:)
编辑2:
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