Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

DataRows, String Indexes and case sensitivity with Turkish Locale


:P
On this page:

I’ve been tracking a really funky bug in my West Wind Web Store application that seems to crop up only very infrequently in my error logs. Basically the problem is that for some odd reason a field in a DataRow that indeed exists is not being found. In that previous post I mentioned that I had instituted some additional logging features – specifically making sure that I would also log the locale of the user accessing the application.

 

Well, 3 bug reports later I noticed that all errors occurred with a Turkish (tr) browser. So I changed my browser’s default language to Turkish and sure enough I could see the error occur. The code that causes the error is here:

 

public String Itemimage

{

      get

      {

            if (this.DataRow == null)

                  return this._Itemimage;

 

            if (this.UseColumns)

                  return (String) this.DataRow[this.ItemimageColumn];

            else

                  return (String) this.DataRow["Itemimage"];

      }

      set

      {

            if (DataRow != null)

                  this.DataRow["Itemimage"] = value;

           

            this._Itemimage = value;                             

      }

}

 

Seems harmless enough and it works 99% of the time. But when I run with Turkish browser language simulation check out what I get in the debugger here:

 

The code fails when the fieldname is in mixed case. If I change the field to lowercase only it works fine!!! If I run the same code with most other language impersonations – no problemo. Only in Turkish (so far as I can tell).

 

Now I should mention that my Web app changes locale on each request to match the user’s locale so that numeric and date values display in their proper locale formats without me having to explicitly do this.

 

Now why is this failing? In some languages upper and lower case letter apparently have different meanings and they don’t quite refer to the same thing. I’m not familiar with the Turkish Alphabet treatment, but I seem to remember from a localization lecture a long while back that some alphabets treat upper and lower case differently.

 

What’s odd is that there are several other field accesses prior to this one and all of those actually work fine. However, this is the only field that starts with an I.

 

The code for the field values is generated so the fix in this case is easy – just re-generate the code and force all lower case characters. Nevertheless this is a very scary proposition, which is now making me think hard about using visitor language impersonation on my requests.

 

I’m just running through my entire app with the Turkish browser setting and since every request automatically switches locale it’s interesting to see all the places code is broken due to this particular bug. It’s not just DataRows, but also table names in DataSets – basically anything with a string based indexer has a potential problem with this code.

 

Learn something new every day.


The Voices of Reason


 

Rich
May 24, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

>>>The code for the field values is generated so the fix in this case is easy – just re-generate the code and force all lower case characters. <<<

But what if there's another language which turns out to need "I" or some other letter in uppercase?


Rick Strahl
May 24, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

Well I said this was the 'quick' fix.

I'm not sure what the real solution is. Actually it turned out that my quick fix wasn't quite enough. I have lots of instances of indexed properties that start with an I like DataSet table references etc. It's really hard to be consistent with that.

I'm fairly confident though that forcing lower case on indexes would solve this problem. But it's a bit unrealistic after the fact <g>...

The other solution is to turn off the thread locale switching. With that off the error disappears completely as well. The alternative would be to fix up any data and numeric values manually.

Maybe somebody from Turkey can clarify how the alphabet works and most importantly how they deal with indexed values in their applications. I would guess they are more disciplined <g>.



Rick Strahl
May 24, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

So actually my fix up solution at the moment is to check for turkish locale before switching locales and if it's turkish not to switch. We'll see if that fixes the problem or whether other locales pop up later.

Craig McGuff
May 24, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

There is a kbalert on something similar for datasets, maybe a similar problem/solution.

basically, there is a case sensitive index and a case insensitive index and they don't always seem to get updated...

solution is to copy the dataset to itself with ds=ds.Copy()

I don't know if you can do this with DataRows though.

http://www.kbalertz.com/kb_815545.aspx

Rick Strahl
May 25, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

Craig,

Interesting, but that's an unrelated problem. The issue here is clearly that the letter I has a different meaning in upper and lower case in the Turkish alphabet. Most other fields work fine in mixed case.

Justin graf
May 25, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

Not much help but can confirm this error has been thrown on my server with

along with a very similar error

-------Begin Error-------

/webstore/item.aspx?sku=MLA-5-50

Column 'Image' does not belong to table wws_items.
on 15.03.2005 14:55:46

--- Stack Trace ---
at System.Data.DataRow.get_Item(String columnName)
at DataRowContainers.wws_itemsRow.get_Image()
at Westwind.WebStore.Item.DisplayItem() in w:\wwWebStore\item.aspx.cs:line 129
at Westwind.WebStore.Item.Page_Load(Object sender, EventArgs e) in w:\wwWebStore\item.aspx.cs:line 57
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain()

--- Request Information ---
Full Url: http://www.emproshunts.com/webstore/item.aspx?sku=MLA-5-50
IP: 81.214.122.121
Referer: http://www.emproshunts.com/webstore/ItemList.aspx?Category=MLA
Browser: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; SV1)
Login: Anonymous

-----end Error--------

I went and did an IP look up, its from Turkey


If you want me to i can compare my error logs to geo location..

Now your going to love this from confirmed ips comming from turkey their are a total of 61 hits there is a total of 64 errors on the server????

that matches a little to close ????

Weston M. Binford III
May 25, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

This will probably not solve your problem, but it might send you down the right path. There are two letters in the Turkish alphabet that we would call I. There is an i with a dot on top that corresponds to the i in English and there is an i without a dot on top.

To distinguish, the capital letter I (with the dot) also has a dot. Thus, in Turkish, I (without the dot) is not the capital version of i, but is the capital version of i (without the dot).

I suspect that somewhere along the way, the case-sensitivity of the key is being removed. When, it is re-applied, then, the wrong I (the one without the dot) is being used.


Yan
June 18, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

I'm not from Turkey, but if you run a search in Google for "turkish alphabet" you'll easily see why the problem with this letter is appearing. See http://www.onlineturkish.com/alphabet.asp

Vishal - vishal_dattani@yahoo.com
July 22, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

Hi Rick ,

ur right about the turkish language problem. even i m faced with a similar problem.
there is a link which does mention about this in msdn but no solution to solve it except tht not to use casing with these cultures.. a bit too late for us i think :-)

http://msdn.microsoft.com/msdnmag/issues/05/03/CultureInfo/default.aspx

regards
Vishal

Eagle
September 15, 2005

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

I have the same or a similar problem.

I noticed one day that I could not log into my website and got this error: "column somethine does not...".

But when I tried this from my local version of the site this didn't happen.

Both the local and the hosted version were connecting to the same SQL server that is hosted at the same company as the website.

How is this possible, and this happens only occasionally ?

Is this the same problem you were facing or a problem with the hosting itself ?

Rick Strahl's WebLog
January 10, 2006

# Hungarian Characters and DataRow String Field indexes

One more time I've run into an issue where I'm reading a field from a DataRow only to find that the current Locale I'm running in doesn't like the field name and fails to retrieve the field. This time it's Hungarian which seems to have some odd combinations that do and don't work.

Rick Strahl's Web Log
September 28, 2006

# ADO.NET Missing Field in a DataRow error driving me crazy - Rick Strahl's Web Log

I'm still struggling with an odd error that's causing a field to not be returned in a DataRow from a SELECT * query. Other fields are there, but for some odd reason under very rare circumstances that I haven't been able to trace the field is missing. Maybe somebody can see the error of my ways, as my sleuthing has run into the end of the line...

Rick Strahl's Web Log
September 28, 2006

# Detecting and setting the Locale on the Current ASP.Net Web Request - Rick Strahl's Web Log

Here's a useful tip on how to switch the Locale in your Web Applications to provide proper number and date formatting for users from different countries. Detect the Locale and then switch the current request to this Locale to provide a more customized user experience.

Rick Strahl
October 05, 2006

# Detecting and setting the Locale on the Current ASP.Net Web Request - Rick Strahl

Here's a useful tip on how to switch the Locale in your Web Applications to provide proper number and date formatting for users from different countries. Detect the Locale and then switch the current request to this Locale to provide a more customized user experience.

luis Zavaleta
February 22, 2008

# re: DataRows, String Indexes and case sensitivity with Turkish Locale

I'm having the same problem and I'm not Turkey, I'm mexican!!!, and I have my browser in spanish. I'm working with visual studio I hate microsoft

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024