Converting UTF8 data to UCS2 [Resolved]


 I am currently translating a database into several languages using Unicode on SQL Server 2000.  The field types being populated are nvarchars.  Originally I used a program to drive windows to repeatedly access Babelfish,  grab the translated text and write that text to a UTF-8 encoded text file.  Opening this file in notepad as UTF-8,  and then saving as 'Unicode' allows the data to be imported quite happily into the database.  In this way,  I have successfully translated over a 1000 different screen texts and help screens.

I am now writing a maintenance program to keep the various texts updated and I can successfully get the translated text in UTF-8 format,  however,  no matter what I try,  I cannot get this text into SQL Server since I appear not to be using the correct character conversion.

 SQL Server nvarchars use UCS-2 as their character set which apparently is a little endian restricted version of UTF16.  Apparently the 'Unicode' property of system.text.encoding generates UCS-2 characters however,  it appears that the way I'm doing it is lacking in some respect.

The code I have is as follows:

   Sub B02_Click(sender As Object, e As EventArgs)
       Const CP_UTF8     As Integer = 65001
       Dim UpdList       As New ArrayList()
       Dim Ie_Upd        As IEnumerator
       Dim tRow          As New TableRow
       Dim tCell         As New TableCell
       Dim RowsU         As Integer
       Dim Sid           As String
       Dim Spras         As String
       Dim UCS2_String   As String
       Dim UCS2_Bytes()  As Byte
       Dim UCS2_Coding   As System.Text.Encoding
       Dim UTF8_String   As String
       Dim UTF8_Bytes()  As Byte
       Dim UTF8_Coding   As System.Text.Encoding
       Dim Trans_Cnt     As Integer
       Sid = Get_Single_Sid()
       Spras = Get_Spras()
       UpdList = Cache("UPDLIST")
       Ie_Upd = UpdList.GetEnumerator
       While Ie_Upd.MoveNext
             Call Update_Job_Status(Sid, Message("1132", Spras, Ie_Upd.Current.MsgNo, Ie_Upd.Current.Spras))
             '* Change the returned text from UTF-8 to the Unicode that MS-SQL supports
             UTF8_String = Ie_Upd.Current.MsgTx
             UTF8_Coding = System.Text.Encoding.UTF8
             UTF8_Bytes  = UTF8_Coding.GetBytes(UTF8_String)
             UCS2_Coding = System.Text.Encoding.Unicode
             UCS2_Bytes  = System.Text.Encoding.Convert(UTF8_Coding, UCS2_Coding, UTF8_Bytes)
             UCS2_String = UCS2_Coding.GetString(UCS2_Bytes)           
             RowsU = Run_Sql("exec sp_Insert_Auto_Messages @MsgNo = "   & Quote(Ie_Upd.Current.MsgNo) & ", " & _
                                                           "@Spras = "   & Quote(Ie_Upd.Current.Spras) & ", " & _
                                                           "@MsgText = " & Quote(UCS2_String))
             tRow = New TableRow
             If RowsU > 0 then
                tRow.Cells.Add(Table_Cell("<div class=" & Quote("vet_green") & ">" & Message("1130", Spras) & "</div>"))
                tRow.Cells.Add(Table_Cell("<div class=" & Quote("vet_Red") & ">" & Message("1131", Spras) & "</div>"))
             End If
       End While
       tRow = Nothing  
       Ie_Upd = Nothing
       B01.Visible = True
       L02.Visible = False
       MsgList.Visible = False
       B02.Visible = False
       L06.Visible = True
       UpdResults.Visible = True
   End Sub






 SQL server requires an 'N' prefixed to Unicode strings.  Therefore by changing the Quote() function called in the Run_Sql line to append an 'N' to the front of the string worked.

Can someone tell me where I'm going wrong please.



10/6/2007 5:50:23 PM 29906 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 14


Similar Artilces:

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

convert an sql datetime column to .net datetime data type in front end...?
I have a field (ldate) in a table that typically displays data in the following format:2007-11-12 20:30:47.000In the front end I want the time and the date separately. But as I try to cast it to a datetime object it is giving me a System.NullReferenceException. What I tried to do was just this: Protected Sub gvTopics_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvTopics.RowDataBound Dim img As Image = gvTopics.FindControl("imgIcon") Dim lbDate, lbTime As Label lbDate = gvTopics.FindControl(...

The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later.
I am getting error like The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later. i am working with windowsXP. Already in my system i have MDAC 2.7. I donot know why am i getting error like this. anybody help me please...

SQL 5.5 cp850 convert to SQL 11 utf8 DB
We can unload a Database from SQL Anywhere Vers. 5.5 into a SQL 11 Database with the collation cp850 (charset Windows-1252) with the unload-utility from Sybase SQL Anywhere 11. But we don't can convert this SQL Anywhere 11 cp850 database in a SQL Anywhere UTF-8 database. From Version 9.0 to 11.0 it works. We have try: dbunload -c "uid=3ddba;pwd=3dXXX;charset=3dcp850;dbf=3dcustomer.db" -ac "uid=3ddba;pwd=3dsql;charset=3dUTF-8;dbf=3dnewsql11.db" -xx The dbunload.exe have some problems with special signs (=e4,=f6,=fc etc.) Can yo...

How to Data Transfer From Excel to Microsoft SQL Server Data base Using .Net.
Hai All, How to Data Transfer From Excel to Microsoft SQL Server Data base Using .Net. I have one Excel Sheet in that sheet 15 Fields (attributes) and 3000 records are there. In this 3000 records i want to store this (Excel) data into  5 related tables on Sql Server Database Using .Net.   How to store Excel Sheet data into Sql Server database. Please help me as soon as possible. Thank You Very Much...Have a Good Day... With RegardsSridhar...

how do i insert data into sql server using data from textboxes and sql connection and sql command
anyone can give me a simple explaination and code.. Thanx in advance Take a look @ Sample Code: How to add...Sushila Bowalekar PatelVisual ASP/ASP.NET MVP There are a lot of tutorials out there, but I know they can be a bit confusing as they all approach things slightly differently. Basically a nice simple version would go like this:' *** First set up your connectionDim conConnection As New SqlConnection("server=servername;database=yourdatabase;uid=yourname;pwd=yourpassword;")' *** This line takes care of your sommand text and command connection in one ...

Connectivity problem with IIS 6 mode ASPX and SQL Anywhere .NET Data Provider iAnywhere.Data.SQLAnywhere SAConnection
This is a multi-part message in MIME format. ------=_NextPart_000_0013_01CABC4F.394AC480 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: quoted-printable Connectivity problem with IIS 6 mode (Windows 2003) and Sybase = SQLAnywhere Web Edition with SQL Anywhere .NET Data Provider = (iAnywhere.Data.SQLAnywhere iAnywhere.Data.SQLAnywhere.SAConnection() ) using aspx. When I try to connect to Sybase SQLAnywhere Web Edition database from = aspx using SQL Anywhere .NET Data Provider (iAnywhere.Data.SQLAnywhere iAnywhere.Data.SQLAnywhere.SAConn...

SQL Data Convertion error??
HI, I'm encouter some data convertion string problem especially during database update use ( Please help advice how can i solve the error?? I guess integer value need convert to string before able execute update function.. The error i get: - 1) failed to convert nvarchar to int 2) Convertion string is not in correct format... let say i drag a textbox (txtquantity) and allow input and click update (with call procedure) updatexx set quantity=2 select from YY. Wondering if i missed some important code?? Another data converting errorsituation is: let say i create a...

converting to from offered me some sample code when I signed up with them the only problem is the sample code is in but my page that they type all of their credit card into is <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage(""); } private String readHtmlPage(string url) { ...

Converting utf8 data to base64 encoding
------=_NextPart_000_0096_01C32448.4CEFB910 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi I have been encountering a problem with the MIME::Base64 = encode_base64 function. Whenever I try to print a (non-ASCII) utf8 = string, I get the error "Wide character in print". Can you help me in = sorting out this problem? Thanks.. Lavanya ------=_NextPart_000_0096_01C32448.4CEFB910-- ...

Net::LDAP::LDIF and UTF8 data
Hi! Since attribute values should be UTF-8 encoded, shouldn't Net::LDIF convert values that are "character-strings" explicitly to UTF8? --- 2004-07-29 15:45:25.000000000 +0200 +++ 2004-07-29 15:44:54.000000000 +0200 @@ -296,7 +296,9 @@ my $ln = $lower ? lc $attr : $attr; if ($v =~ /(^[ :]|[\x00-\x1f\x7f-\xff])/) { require MIME::Base64; - $ln .= ":: " . MIME::Base64::encode($v,""); + use Encode; + $ln .= ":: " .MIME::Base64::encode( + Encode::is_utf8($v)? encode...

Convert Gridview Data in to PDf file. or Convert report data in pdf file
 Hi have problem to convert Gridview data into PDF file..let me know is there any solution or open source components..Regards Rambhopal Reddy EPlease remember to click “Mark as Answer” on the post that helps you, and to click “Unmark asAnswer” if a marked post does not actually answer your question. Friend, Check this thread for soultions and then to   Good luck!     Please Don't forget to click "Mark as Answer" on the post that helped you.This can be benef...

Convert javascript data to .net objects
 Hi!I have some js data: integers, strings, objects that is dynamicaly  created on web page by js functions. I need to post this data to server side to process it in my C# code. I wonder are there any othrer way of doing that, except assigning all data to hidden value and then parsing it as a string on the server side? Maybe some tool like DWR in java to convert js objects to POCO objects?  Well you need to get the data to the server. And the only way to do it is to pass it up as a form parameter. So you either have to usea hidden field with a tradional postback or you use a...

Converting ACCESS and EXCEL data to SQL
Hi, I have some tables in an ACCESS database, and would like to recreate them in a SQL2005 databse.How may this be done?I am able to create a Data Component with the ACCESS mdb file. Likewise, how may I convert EXCEL data to SQL2005 table?Thanks. David   Access should have an upsizing wizard look for it, excel try the link and code below.  Hope this helps. /* Excel as a linked server *//* Assuming we have an Excel file 'D:\testi\Myexcel.xls'    with following data in the first sheet: id name  1 a  2 b&n...

Web resources about - Converting UTF8 data to UCS2 [Resolved] -

Facebook Begins Converting Users To HTTPS
Are you willing to sacrifice a little bit of speed for a lot more safety? Facebook is asking that very question with its announcement that it ...

Facebook No Longer Converting Groups Into Pages
Back when Facebook first launched Facebook Pages, many businesses and brands who had built up substantial audiences in their Facebook Groups ...

Vert - simply converting for iPhone, iPad, and iPod touch on the iTunes App Store
Get Vert - simply converting on the App Store. See screenshots and ratings, and read customer reviews.

Converting SIM Card to Micro SIM Card - Flickr - Photo Sharing!
Place new Micro SIM into the iPhone SIM card tray

Ayaan Hirsi Ali on Converting Muslims to Christianity - YouTube
Complete video at: Ayaan Hirsi Ali explains her support of missionary ...

Click go fears of converting print files
Is there a way to convert a print queue item to a .RTF or .PDF file? I like to save or email them. - The Sydney Morning Herald

Sudanese woman ordered to hang under sharia law for converting to Christianity gives birth
Khartoum, Sudan: A Christian Sudanese woman sentenced to hang for apostasy has given birth in jail, a Western diplomat said on Tuesday.

Imams warn against radicalism to Aboriginal inmates converting to Islam
The prison system has enlisted the help of ASIO to crack down on radicalisation behind bars amid revelations that Aboriginals are converting ...

Converting the world's companies one by one - The Science Show - ABC Radio National (Australian Broadcasting ...
Image: Trucks carrying logs make their way up a road in Jambi, Indonesia. A vast area of the Sumatran forest, and orangutan habitat, is being ...

Converting Churches Into Homes Is The Latest Hollywood Trend
You don't have to be a believer to be moved by the beauty of a church.

Resources last updated: 12/24/2015 8:17:51 PM