Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C FreeTDS:如何设置运行存储过程的参数字符集_C_Sql Server_Linux_Character Encoding_Freetds - Fatal编程技术网

C FreeTDS:如何设置运行存储过程的参数字符集

C FreeTDS:如何设置运行存储过程的参数字符集,c,sql-server,linux,character-encoding,freetds,C,Sql Server,Linux,Character Encoding,Freetds,我有一个C程序通过连接到MSSQL数据库 我试图执行一个存储过程,将varchar参数设置为类似“Saída Liberada”的值,但它在MS SQL中以奇怪的字符存储,如屏幕截图所示: 这是我的freetds.conf: # $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $ # # This file is installed by FreeTDS if no file by the same # name is f

我有一个C程序通过连接到MSSQL数据库

我试图执行一个存储过程,将varchar参数设置为类似“Saída Liberada”的值,但它在MS SQL中以奇怪的字符存储,如屏幕截图所示:

这是我的freetds.conf:

#   $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
        tds version = 8.0

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
        dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512

        client charset = UTF-8
以下是tds转储文件的部分内容:

log.c:196:Starting log file for FreeTDS 0.91
        on 2016-05-17 19:19:41 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xaed19130, ISO-8859-1)
iconv.c:353:Using trivial iconv
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "ISO-8859-1"
iconv.c:351:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "ISO-8859-1" conversion
iconv.c:394:tds_iconv_open: done

...

net.c:741:Sending packet
0000 01 01 00 84 00 00 00 00-20 45 58 45 43 20 55 50 |........  EXEC UP|
0010 5f 49 4e 53 45 52 54 4d-4f 56 49 4d 45 4e 54 4f |_INSERTM OVIMENTO|
0020 20 27 32 30 31 36 2d 30-35 2d 31 37 20 31 39 3a | '2016-0 5-17 19:|
0030 31 39 3a 33 31 2e 30 30-30 27 2c 27 30 30 30 30 |19:31.00 0','0000|
0040 30 30 30 30 30 30 36 34-38 33 30 35 37 30 33 30 |00000064 83057030|
0050 27 2c 27 53 27 2c 30 2c-32 2c 27 50 43 56 43 30 |','S',0, 2,'PCVC0|
0060 34 20 3d 20 53 61 c3 ad-64 61 20 4c 69 62 65 72 |4 = Sa.. da Liber|
0070 61 64 61 27 2c 34 2c 27-50 43 56 43 4d 41 4e 41 |ada',4,' PCVCMANA|
0080 47 45 52 27            -                        |GER'|
更新2

要连接的代码:

ret = SQLDriverConnect(db_msserver_dbc_handle,
    NULL,  "Driver={FreeTDS};Server=FooBar;Port=1433;Database=Foo;UID=sa;PWD=pwd@123;APP=XPTO;TDS_Version=8.0;",
    SQL_NTS, outstr, sizeof(outstr), &outstrlen,
    SQL_DRIVER_COMPLETE);

经过多次尝试,我无法理解为什么freetds.conf设置(客户端字符集和tds版本)没有得到尊重。至少,当我附加TDS_Version=8.0时;ClientCharset=UTF-8进入,它可以工作

此外,freetds日志文件的标头也发生了更改,其中提到了UTF-8转换:

log.c:196:Starting log file for FreeTDS 0.91
        on 2016-05-18 15:58:49 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xaeb19118, UTF-8)
iconv.c:353:Using trivial iconv
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:394:tds_iconv_open: done
log.c:196:启动FreeTDS 0.91的日志文件
在2016-05-18 15:58:49,带有调试标志0x4fff。
iconv.c:330:tds_iconv_打开(0xaeb19118,UTF-8)
iconv.c:353:使用平凡的iconv
iconv.c:187:ISO-8859-1的本地名称为ISO-8859-1
图标c:187:UTF-8的本地名称为UTF-8
图标编号c:187:UCS-2LE的本地名称为UCS-2LE
图标编号c:187:UCS-2BE的本地名称为UCS-2BE
iconv.c:349:为客户端字符集“UTF-8”设置转换
iconv.c:351:为“UTF-8”“UCS-2LE”转换准备iconv
iconv.c:391:为“ISO-8859-1”“UCS-2LE”转换准备iconv
iconv.c:394:tds_iconv_打开:完成

经过多次尝试,我不明白为什么freetds.conf设置(客户端字符集和tds版本)没有得到尊重。至少,当我附加TDS_Version=8.0时;ClientCharset=UTF-8进入,它可以工作

此外,freetds日志文件的标头也发生了更改,其中提到了UTF-8转换:

log.c:196:Starting log file for FreeTDS 0.91
        on 2016-05-18 15:58:49 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xaeb19118, UTF-8)
iconv.c:353:Using trivial iconv
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:394:tds_iconv_open: done
log.c:196:启动FreeTDS 0.91的日志文件
在2016-05-18 15:58:49,带有调试标志0x4fff。
iconv.c:330:tds_iconv_打开(0xaeb19118,UTF-8)
iconv.c:353:使用平凡的iconv
iconv.c:187:ISO-8859-1的本地名称为ISO-8859-1
图标c:187:UTF-8的本地名称为UTF-8
图标编号c:187:UCS-2LE的本地名称为UCS-2LE
图标编号c:187:UCS-2BE的本地名称为UCS-2BE
iconv.c:349:为客户端字符集“UTF-8”设置转换
iconv.c:351:为“UTF-8”“UCS-2LE”转换准备iconv
iconv.c:391:为“ISO-8859-1”“UCS-2LE”转换准备iconv
iconv.c:394:tds_iconv_打开:完成

Hum,它只是传递给SQLBindParameter的一个文本字符*。。。我原以为FreeTDS会处理好的。我已经用更多信息更新了这个问题。试着将tds版本设置为8.0看看,这只是传递给SQLBindParameter的文字字符*。。。我原以为FreeTDS会解决这个问题。我已经用更多信息更新了这个问题。尝试将tds版本设置为8.0查看连接字符串中的
tds\u version=
是什么为我解决了这个问题。谢谢连接字符串中的
TDS\u Version=
为我修复了它。谢谢
log.c:196:Starting log file for FreeTDS 0.91
        on 2016-05-18 15:58:49 with debug flags 0x4fff.
iconv.c:330:tds_iconv_open(0xaeb19118, UTF-8)
iconv.c:353:Using trivial iconv
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1
iconv.c:187:local name for UTF-8 is UTF-8
iconv.c:187:local name for UCS-2LE is UCS-2LE
iconv.c:187:local name for UCS-2BE is UCS-2BE
iconv.c:349:setting up conversions for client charset "UTF-8"
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion
iconv.c:394:tds_iconv_open: done