如何为 tclodbc 定义驱动程序? [英] How to define a driver for tclodbc?
问题描述
我想使用 Linux 环境中的 tclodbc 连接到 MS SQL 服务器.我有驱动程序(freeTDS)和连接字符串.但是我不知道如何配置tclodbs使用的驱动程序.有一个命令
I want to use tclodbc from Linux environment to connect to a MS SQL server. I have the driver (freeTDS) and the connection string. But I don't know how to configure the driver to be used by tclodbs. There is a command
数据库配置 操作驱动属性
但我不知道应该把什么作为operation
和attributes
,以及这是否是正确的命令.
But I don't know what to put as operation
and attributes
, and whether this is the right command.
与我的问题相关:从运行在 GNU/Linux 上的 Tcl 访问 Microsoft SQL Server
推荐答案
好的,这是我基于 这些 指南关于如何使用 FreeTDS 建立无 DSN 的连接司机.
OK, here's my take based on these guides about how to make a DSN-less connection using the FreeTDS driver.
我测试了一个 Debian Lenny 系统,它具有 tclodbc
2.5-5、unixodbc
2.2.11 和 libdbd-freetds
0.8.2-1-4.1 和 tcl
8.4.16-2 针对 Microsoft SQL Server 2005 的实例安装.
I've tested it a Debian Lenny system having tclodbc
2.5-5, unixodbc
2.2.11 and libdbd-freetds
0.8.2-1-4.1 and tcl
8.4.16-2 installed against an instance of Microsoft SQL Server 2005.
package require tclodbc
proc cs_append {varName args} {
set alen [llength $args]
if {$alen < 2 || $alen % 2 != 0} {
return -code error "Wrong # args: should be varName key value ?key value?"
}
upvar 1 $varName qs
foreach {key value} $args {
if {$qs ne ""} {
append qs \;
}
append qs $key = \{ [string map {\{ \\\{} $value] \}
}
}
set user test
set pass secret
set cs ""
cs_append cs DRIVER FreeTDS UID $user PWD $pass \
Server myserver.domain.local \
ClientCharset UTF-8 \
APP "My test app"
database connect db $cs
foreach row [db {select * from MyDatabase..MyTable}] {
puts $row
}
db disconnect
一些注意事项:
- 通过在
/etc/odbcinst.ini
文件中注册 FreeTDS 驱动程序,ODBC 子系统必须知道它.我想至少在我的系统上,适当的软件包会自己处理这个问题,但您最好验证是否在该文件中注册了 FreeTDS,否则连接字符串中的DRIVER=FreeTDS
位将不会'因为 ODBC 不知道如何加载指定的驱动程序库. ClientCharset
和APP
连接字符串参数在我的情况下不起作用.虽然我可以忍受第二个,但第一个很费时间,因为在这种情况下,字符数据以某种拙劣的编码返回.
- The FreeTDS driver must be known to the ODBC subsystem by means of it being registeded in the
/etc/odbcinst.ini
file. I suppose that at least on my system appropriate packages take care of this by themselves but you'd better verify if you have FreeTDS registered in that file, otherwise thatDRIVER=FreeTDS
bit in the connection string won't work as ODBC will have no idea how to load the named driver library. The
ClientCharset
andAPP
connection string parameters do not work in my case. While I can live with the second, the first one sucks big time because in this case the character data is returned in some botched encoding.
但是当我使用 /etc/freetds/freetds.conf
文件中的命名服务器使用 ServerName=THAT_SERVER
而不是 Server=SERVER_HOST
在连接字符串中.不幸的是,这种使用无 DSN 设置的目的达不到一半.
But there's no such problem when I use named server from the /etc/freetds/freetds.conf
file using the ServerName=THAT_SERVER
instead of Server=SERVER_HOST
in the connection string. Unfortunately, this kind of defeats half of the purpose of using DSN-less setup.
这很可能是我的 FreeTDS 驱动程序版本中的一个错误,而且我这里的系统非常过时,所以 YMMV 和您最好检查一下您的系统.
Quite possibly it's a bug in my version of the FreeTDS driver, and I have a really outdated system here, so YMMV and you better check yourself on your system.
这篇关于如何为 tclodbc 定义驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!