Groups | Blog | Home
all groups > dotnet datatools > august 2005 >

dotnet datatools : How does .NET Data Provider for SQL Server convert varchar data to Unicode?


Glenn
8/15/2005 12:00:00 AM
After executing a select query the data provider returns the value in a
varchar field to a .NET string, how does it determine the encoding
conversion to perform? My guess is that it's determined by the collation
setting on the column, but I'm not sure? For example, if the collation is
SQL_Latin1_General_CP1_CI_AS, the Provider converts from code page 1252 to
Unicode.
Does anyone know for sure the strategy applied here?

Mark Ashton
8/19/2005 4:58:03 PM
For SqlClient that is true. The code page comes from the server and then
SqlClient uses the System.Text.Encoding.GetString(byte[]) method to convert
to Unicode.

--
This posting is provided "AS IS", with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

[quoted text, click to view]

Glenn
8/22/2005 12:00:00 AM
Mark, do you know if this is also true for the OLE Data Provider for .NET
when querying a SQL Server database?

[quoted text, click to view]

Sylvain Lafontaine
9/3/2005 12:00:00 AM
No, the collation setting is not used for the conversion between Unicode and
an 8 bits code page and vice versa. Collation orders are only used on the
SQL-Server for comparing the equality or the sort order between two strings
and are never used for conversion between a particular code page and
Unicode.

My guess would be that the code page setting for Window on the served would
be used; however, at today's price for hard drives, you shouldn't use
varchar anymore on the SQL-Server. If you are concerned with non-latin (8
bits) caracters, the use of varchar will be a continuous moving target.

See the following articles for more information:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql2k/html/sql_dataencoding.asp

http://support.microsoft.com/default.aspx?scid=kb;en-us;322112

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC


[quoted text, click to view]

AddThis Social Bookmark Button