Re: UTF-8 encoding in AJAX web application.



On Mar 21, 8:40 am, "Allan Ebdrup" <ebd...@xxxxxxxxxxxxxxx> wrote:
No - the driver will do that for you.

Is this done by detecting the UFT8 preamble? And the the driver converts to
UCS-2? And if so how come the result is still in UTF-8 when I retrieve the
data again?

It's done by passing in strings as the parameters. At that stage
there's no encoding involved (well, sort of - all .NET strings are
actually UTF-16, which is very similar to UCS-2, but you can
effectively ignore that). In particular, it is meaningless to say that
a string (as a System.String) is "UTF-8 encoded".

Why is it important that MSSQL only supports UCS-2 unicode if everything
works fine with UTF-8?

That's the internal storage format, that's all. (It may mean you can't
support characters not in the Basic Multilingual Plane, but it's not
worth worrying about that at this stage.)

I can see that everything works fine when storing a UTF-8 string in an ntext
column, and when I query the data in queryanalyzer the string is displayed
correctly in the result set, how can this be if MSSQL only supports UCS-2
encoding?
How is the string stored? in UTF-8 or UCS-2?

UCS-2 in the database. When you fetch it from the database, the driver
will convert it into a .NET string for you.

The main point is that so long as you use parameters/queries which
just use strings, you shouldn't need to worry about it at all in your
code: so long as you start with the right string (wherever it came
from) it should be stored correctly.

Sorry for all the questions, I'm just tryng to understand what's going on.

Have you read http://pobox.com/~skeet/csharp/unicode.html ? It may
help.

Jon

.



Relevant Pages

  • Re: UTF-8 encoding in AJAX web application.
    ... But I should really convert from UTF-8 to UCS-2 before saving ... No - the driver will do that for you. ... And if so how come the result is still in UTF-8 when I retrieve the ... I can see that everything works fine when storing a UTF-8 string in an ntext ...
    (microsoft.public.dotnet.languages.csharp)
  • Converting to UCS-2 or UTF-16 for use by a C extension
    ... to convert a Ruby input string into UCS-2 or possibly UTF-16 encoding. ... encoded internally as UTF-8... ...
    (comp.lang.ruby)
  • Re: UTF-8 encoding in AJAX web application.
    ... you can do is set the collation. ... what collation should I use to be able to use UCS-2? ... I was thinking I could convert my UTF-8 encoded string to UCS-2 and save it ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Unicode Delphi Win32 - which approach
    ... I like the backwards compatibility aspects of UTF-8 vs UTF-16. ... The first 256 Unicode characters map to the ANSI character set. ... entire stream> but calling an API 100 times in a loop I can imagine. ... and explicitly contextualise every string. ...
    (borland.public.delphi.non-technical)
  • Re: UTF-8 encoding
    ... I need to pass a UTF-8 encoded writer ... reading that file with the system's default encoding. ... String), but used elsewhere as if it were a StringBuffer. ... There's a very good reason that ...
    (comp.lang.java.programmer)