| Author |
Saving Unicode in SQL using ASP
|
|
| hilio@cambridgesoft.com 2005-08-18, 5:55 pm |
| I have an asp application that should allow the user to enter Unicode
characters.
The characters appear correctly in the browser.
When saved in sql 2000 thought they are converted to question marks
etc.
When I enter the characters directly in SQL (using enterprise manager),
they appear correctly in sql as well as in the browser when the asp
page retrieves them.
As soon as I hit save they get overwritten in sql incorrectly.
Any help would be appreciated.
Thanks
| |
| Aaron Bertrand [SQL Server MVP] 2005-08-18, 5:55 pm |
| What does your UPDATE / INSERT statement look like? Are you prefixing your
strings with N prefix to denote Unicode or, better yet, using a Command
object with the correct parameter type?
<hilio@cambridgesoft.com> wrote in message
news:1124375891.817679.74600@o13g2000cwo.googlegroups.com...
>I have an asp application that should allow the user to enter Unicode
> characters.
>
> The characters appear correctly in the browser.
> When saved in sql 2000 thought they are converted to question marks
> etc.
> When I enter the characters directly in SQL (using enterprise manager),
> they appear correctly in sql as well as in the browser when the asp
> page retrieves them.
> As soon as I hit save they get overwritten in sql incorrectly.
>
> Any help would be appreciated.
> Thanks
>
| |
|
| I didn't know that my UPDATE/INSERT should look any different. Can you
give an example of what they should look like?
Thanks
| |
| Aaron Bertrand [SQL Server MVP] 2005-08-18, 5:55 pm |
| INSERT table_name(column_name) SELECT N'¥'
You need to determine if the unicode character is getting lost between ASP
pages or between the second ASP page and the call to the
update/insert/stored procedure statement.
A very basic and common debugging technique is to response.write sql instead
of conn.execute sql.
A
"hilio" <hilio@cambridgesoft.com> wrote in message
news:1124379297.372744.63070@g47g2000cwa.googlegroups.com...
>I didn't know that my UPDATE/INSERT should look any different. Can you
> give an example of what they should look like?
>
> Thanks
>
| |
|
| Aaron, thanks for the suggestion. I tried response.write and it
displayed different characters, not the characters that are entered by
the user. Would this indicate that the web server is not interpreting
the characters correctly?
| |
| Mark Schupp 2005-08-18, 5:55 pm |
| first make sure that you are using a character set in the browser that
supports the characters. Then make sure that you are using a code page in
ASP that supports them as well. Simplest way is to use UTF-8
in ASP script
Session.Codepage=65001
then send to browser:
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
Now you should see the same characters back when you write the SQL statement
back.
Now you need to get the data into the database. If you have SQLServer set to
a collation that supports your characterset then it should work now. If not,
you will need to use NCHAR or NTEXT columns. Either use a parameterized
command object or when building dynamic SQL prefix the data string with "N"
to tell SQLServer that the data is unicode.
--
--Mark Schupp
"hilio" <hilio@cambridgesoft.com> wrote in message
news:1124383473.309646.193280@g43g2000cwa.googlegroups.com...
> Aaron, thanks for the suggestion. I tried response.write and it
> displayed different characters, not the characters that are entered by
> the user. Would this indicate that the web server is not interpreting
> the characters correctly?
>
| |
|
| Thank you both for the replies.
I implemented your suggestions and it now works. I learned that SQL
requires the N prefix for updates and inserts of UNICODE data.
Thank you all
|
|
|
|