views:

57

answers:

4

My company just converted many columns from varchar to nvarchar.

Now it seems that when we render a smart quote (i.e. ALT+0146 ’) to the screen and then send it back to the SQL Server 2000 database for persistence, the smart quote gets corrupted to - ’ -.

My Question:

How could ASP server-side code corrupt a smart quote ’ ?

EDIT: It appears that my question is similar to this one. Incidentally, Powerpoint content introduced the smart quote into the mix. However as I said before, I'm dealing with an ASP page, whereas the referenced question pertains to a PHP page.

EDIT: The server-side directive CODEPAGE=65001 makes the page render correctly, but it still posts content as 'Western European' on a Windows 2000 box. Does anyone know why?

+2  A: 

It looks like something is doing an implicit conversion between ANSI and Unicode (and choosing the wrong code page in the process). You may need to do the conversion manually and supply the correct code page. It's hard to say without seeing the code.

Peter Ruderman
+2  A: 

Take a look at this:

http://support.microsoft.com/kb/232580

You may want to set your Code Page in the ASP so you don't get hokey characters.

Nissan Fan
+1  A: 

While you do need to tell the server which encoding to use, have you told the client what the page encoding is? If not, the client will happily post in whatever encoding the user last explicitly chose, or a system default encoding, which is likely to be western european on most US or Western European machines.

In your html, do you have something like this in your <head> ?

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

You can also ask the server to send this explicitly in your Response.Headers. Although I think it's a good idea to send it in the HTTP headers, it's helpful to include it in the HTML as well for people who decide to save the document locally for whatever reason.

JasonTrue
+1: Good point. Yes, I *do* have that meta tag inside of the header node. However, I don't think that I've asked the server to send that explicitly in the response header. Is there a configuration setting that I should look at?
Jim G.
Not necessary if you're doing the html method. While I think there is a configuration option for site-wide HTTP headers in IIS, but I don't think it's a good idea to apply it unless you're sure that all pages are handling UTF-8.
JasonTrue
%E2%80%99 is, in fact UTF-8 for the smartquote. Are you using a parameterized query? Is the type on that parameterized query set to SQL's NVARCHAR type? If you're not using a parameterized query, are you using the Unicode marker in your SQL? (e.g. N'mytext')? Finally, you may need to set Request.CodePage=65001 before reading the Form values.
JasonTrue
http://msdn.microsoft.com/en-us/library/ms524967(VS.90).aspx is a good place to check also. (Can't remember if old-school asp supported Request.CodePage; if not, try Session.CodePage).
JasonTrue
A: 

VBScript might mangle the Unicode characters; especially on older versions of IIS (i.e IIS 5.0 on Windows Server 2000).

In my case, a For Each construct was to blame.

Here's some example code that executes after a POST:

Response.Write Request.Form("selOptions")(0) ' A-OK! - Displays Unicode characters fine!  
For Each sOption in Request.Form("selOptions")
  Response.Write sOption ' Bad! Unicode characters are mangled!  
Next

As always, your mileage may vary.

Jim G.