我在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
[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
我需要能够在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
解决方法
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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。