简体   繁体   English

使用NHibernate将汉字保存到oracle中的问题

[英]Problem with saving chinese character into oracle using NHibernate

I am trying to save chinese character into oracle DB using Nhibernate thru C# and the character saved always end up with some rubbish character. 我正在尝试使用Nhibernate通过C#将汉字保存到oracle DB中,并且保存的字符总是以某些垃圾字符结尾。

I have done the following: 我已经完成以下工作:

  1. Hbm mapping for the field is declared as type AnsiString and column type as sql-type="nvarchar". 字段的Hbm映射声明为AnsiString类型,列类型声明为sql-type =“ nvarchar”。 Have also tried String and nvarchar2 too. 也尝试了String和nvarchar2。
  2. Database column data type is NVARCHAR2. 数据库列的数据类型为NVARCHAR2。
  3. Registry, environment variable and database charset NLS_LANG is set to UTF8. 注册表,环境变量和数据库字符集NLS_LANG设置为UTF8。

I am able to read the chinese character input thru sql developer. 我可以通过sql开发人员阅读中文字符输入。 But when I try to retrieve them (the character display correctly on screen) and attempt to save them back into the database without any changes, the data saved became " ". 但是,当我尝试检索它们(字符在屏幕上正确显示)并尝试将它们保存回数据库而不作任何更改时,保存的数据变成了`` ''。

Anyone have any clue what have I miss out here? 有人知道我在这里错过了什么吗?

I would check what the data really is on the .NET side. 我将检查.NET端真正的数据是什么。 Don't trust what's displayed on a console - look at the UTF-16 code points. 不要相信控制台上显示的内容-查看UTF-16代码点。

See my debugging unicode article for the general approach. 有关一般方法,请参见我的调试unicode文章

I seem to remember having some problems in Oracle before which were only fixed by setting the database encoding and then rebuilding the database - I couldn't apply it to an existing one. 我似乎记得在Oracle中遇到过一些问题,这些问题只能通过设置数据库编码然后重建数据库来解决-我无法将其应用于现有的数据库。 However, the details are in the dim and distant past... 但是,细节是在昏暗而遥远的过去...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM