sybase数据库sql带中文运行出错(odbc),除了在下人品,还有可能是什么原因?

yan63 2006-09-05 10:11:30
纯英文运行正常,带中文就出错,愚翁老爷在某帖提示在connectionstring中加上charset = iso_1,还是不行,现只好回家面壁。请各位不吝赐教,拜谢。
ps:具体的错误代码明天回单位帖出来,不知道各位有没有使用odbccommand在sybase运行sql时碰到这样的问题。
...全文
1208 25 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
yan63 2006-09-07
  • 打赏
  • 举报
回复
up
yan63 2006-09-07
  • 打赏
  • 举报
回复
up
Knight94 2006-09-06
  • 打赏
  • 举报
回复
to 貌似解决了这个问题,在.net中将sql由encoding.default编码成encoding.ascii运行就可以了,难道sybase不懂有utf8这样的高级货吗?!!难道是我数据库utf8字符集未安装?

按照这样转,中文字符还能还原吗?
既然参数是可以的,为什么不用呢,这比你手动去转换简单多了。
yan63 2006-09-06
  • 打赏
  • 举报
回复
貌似解决了这个问题,在.net中将sql由encoding.default编码成encoding.ascii运行就可以了,难道sybase不懂有utf8这样的高级货吗?!!难道是我数据库utf8字符集未安装?还是不解。anyway人品是保住了.
附编码转换的代码,抄msdn:
/// <summary>
/// 转换现有字符的编码
/// </summary>
/// <param name="srcString">源字符串</param>
/// <param name="srcEnoding">源字符串编码类型</param>
/// <param name="desEncoding">要转换到的编码类型</param>
/// <returns>转换编码后的字符串</returns>
public string StringEncodingConvert(
string srcString,Encoding srcEnoding,Encoding desEncoding)
{

// Convert the string into a byte[].
byte[] srcBytes = srcEnoding.GetBytes(srcString);

// Perform the conversion from one encoding to the other.
byte[] desBytes = Encoding.Convert(srcEnoding, desEncoding, srcBytes);

// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] desChars = new char[desEncoding.GetCharCount(desBytes, 0, desBytes.Length)];
desEncoding.GetChars(desBytes, 0, desBytes.Length, desChars, 0);
string desString = new string(desChars);

// Display the strings created before and after the conversion.
return desString;

}

调用的代码:
Encoding srcEnoding = Encoding.Default;
Encoding desEncoding = Encoding.ASCII;
string cmd_asc = stringEncodingConvert(cmd1,srcEnoding,desEncoding);
OdbcCommand cmd = new OdbcCommand(cmd_asc,conn,tran);
.......

揭帖,感谢楼上诸位!!!
yan63 2006-09-06
  • 打赏
  • 举报
回复
使用参数接受中文没有问题!!!这不失为一种解决的方法。感谢愚翁!
我再找找看运行中文sql的方法,24小时内揭帖。
Knight94 2006-09-06
  • 打赏
  • 举报
回复
to 表名、字段名都是英文,
...value ('','在这里有一些中文字符'......)

用参数试试

insert yourtable(...) values( @field1, @field2,... )
yan63 2006-09-06
  • 打赏
  • 举报
回复
老爷说的是这篇《.NET通过ODBC连接Sybase数据库的一个小问题》 吧,真是吊足了胃口,打开一看“无法找到该页 您正在搜索的页面可能已经删除、更名或暂时不可用。”faint!!!我跟中国电信拼了!!!
yan63 2006-09-06
  • 打赏
  • 举报
回复
是一条简单的insert语句
表名、字段名都是英文,
...value ('','在这里有一些中文字符'......)
Knight94 2006-09-06
  • 打赏
  • 举报
回复
这有篇类似文章介绍,在sql中出现中文是有问题
参看
http://blog.aspcool.com/default.aspx?page=2
Knight94 2006-09-06
  • 打赏
  • 举报
回复
to 连接串设置charset=iso_1或是没有设置charset,连接成功,但运行中文sql都出错

sql中的中文?表名、字段名还是参数条件
yan63 2006-09-06
  • 打赏
  • 举报
回复
现在是这样:
1.除了iso_1,连接串中charset设置成其他的都报错
2.连接串设置charset=iso_1或是没有设置charset,连接成功,但运行中文sql都出错,提示:
"
{"ERROR [01004] [MERANT][ODBC Sybase ASE driver]String data translation caused data truncation.\r\nERROR [HY000] [MERANT][ODBC Sybase ASE driver][SQL Server]Unclosed quote before the character string '一些中文字符'.\n\r\nERROR [42000] [MERANT][ODBC Sybase ASE driver][SQL Server]Incorrect syntax near " '一些中文字符'.\n" }
"
yan63 2006-09-06
  • 打赏
  • 举报
回复
好的,我都试试看
Knight94 2006-09-06
  • 打赏
  • 举报
回复
例如:
UNICODE_FSS
ISO8859_1
ISO8859_2
Knight94 2006-09-06
  • 打赏
  • 举报
回复
没有道理,工具可以程序不行,那你可以参照我上面给的地址试试其他字符设置
yan63 2006-09-06
  • 打赏
  • 举报
回复
还是出错,ERROR [01000] [MERANT][ODBC Sybase ASE driver][Sybase ASE]Cannot find the requested character set in Syscharsets: name = 'GB_2312'. ERROR [01000] [MERANT][ODBC Sybase ASE driver][Sybase ASE]No conversions will be done

我的连接串:
driver=SYBASE ASE ODBC Driver;NA=server,5000;uid=sa;pwd=;Database=dbName;charset=GB_2312,是不是数据库安装的时候少了这个字符集?可我在sybase自带的sql advantage控制台运行中文sql没有问题啊
Knight94 2006-09-06
  • 打赏
  • 举报
回复
have a try!

charset=GB_2312
yan63 2006-09-06
  • 打赏
  • 举报
回复
感谢Yuna_2z(其实游戏是一艺术,而我只是身陷其中!) ( ) 帮顶和愚翁老爷的作答
在下在connectionstring中设置charset = iso_1时可正常连接数据库,设置charset = gb2312时连接出错,提示“Cannot find the requested character set in Syscharsets: name = 'gb2312'. ERROR [01000] [MERANT][ODBC Sybase ASE driver][Sybase ASE]No conversions will be done”系统无此字符集?请问如何解决?再找找看小刀的解决方法。
Knight94 2006-09-06
  • 打赏
  • 举报
回复
支持中文的charset应该是gb2312

相关资料,参看
http://www.dotnetfirebird.org/documentation/api/1.7/FirebirdSql.Data.Firebird.FbConnection.ConnectionString.html
Yuna_2z 2006-09-05
  • 打赏
  • 举报
回复
UP
yan63 2006-09-05
  • 打赏
  • 举报
回复
数据库属性文件有没有加charset=eucgb
-----------------------------------------
明天回公司查一下,sybase我是第一次做,感谢kissknife(侧身向南边) ,cctaiyang(小刀可乐) 做答。
加载更多回复(5)

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧