使用FreeTDS和Python3.5库PyPyodbc我试图在SQL Server数据库中插入一行(驻留在Windows上)时得到'Byte string too long'
。
在FreeTDS配置文件下,有一个可修改的'text size'
我改为:
[global]
text size = 4294967295
这是配置文件
/etc/freetds/freetds.conf
[global]
tds version = 4.2
text size = 4294967295
[sqlserver]
host = 192.168.0.3
port = 1433
tds version = 8.0
/etc/odbc.ini
[sqlserverdatasource]
Driver = freetds
Description = SQL Server
Servername = sqlserver
Database = MyDB
TDS_Version = 8.0
/etc/odbcinst.ini
[freetds]
Description = MS SQL
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Trace = Yes
TraceFile = /tmp/freetds.log
FileUsage = 1
UsageCount = 1
执行'tsql -C'
:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
执行'/usr/bin/tsql -S 192.168.0.3 -U user'
:
Password:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
执行'odbcinst -j'
:
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/metheUser/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
Python PyPyodbc连接字符串:
connStr = 'DSN=sqlserverdatasource;Database=MyDB;uid=user;pwd=password'
但错误一直出现,我错过了什么?
答案 0 :(得分:1)
我终于找到了问题,除了在TDS_Version = 8.0中设置之外,PyPyodbc中字符缓冲区的分配还不够。我的查询超过3100个字符(至少)。直接更新PyPyodbc以使金额翻倍现在已足够。不确定是否需要四倍。
为什么没有将这个添加到库中?有关详细信息:https://github.com/jiangwen365/pypyodbc/issues/27
感谢@GordThompson帮助我解决问题并在自己的环境中进行测试。