The culture changes inexplicably during an ASP.NET web application request

I have a strange problem when the date format from date fields changes from 04.16.2009 12:00:00 to 04.16.2009 00:00:00. I installed an application to record every stored proc that was launched with the same corresponding date field, if one exists. Here is what happened. You will notice that the format switch is inexplicably halfway.

EXECUTE uspContent_SelectOne '132'
4/16/2009 12:00:00 AM
EXECUTE uspContent_SelectOne '127'
4/16/2009 12:00:00 AM
EXECUTE uspContent_SelectOne '133'
4/16/2009 12:00:00 AM
EXECUTE uspContent_SelectOne '131'
4/16/2009 12:00:00 AM
EXECUTE uspAttachment_SelectAll
EXECUTE uspArticleAuthors_SelectAll_ArticleId '3'
EXECUTE uspArticles_SelectOne '3'
EXECUTE uspAuthors_Letters
EXECUTE uspAuthors_Letters
EXECUTE uspAuthors_Letters
EXECUTE uspAuthors_SelectAll_Letter_LastName 'A'
EXECUTE uspFiles_SelectAll_NoFileData
EXECUTE uspArticles_SelectOne '3'
EXECUTE uspArticleTypes_SelectAll
EXECUTE uspFiles_SelectAll_NoFileData
EXECUTE uspAuthors_SelectOne '0'
EXECUTE uspArticleAttachments_SelectAll_ArticleId '3'
EXECUTE uspArticleAttachments_SelectOne_ArticleId_AttachmentId '3','4'
EXECUTE uspAttachment_SelectOne '4'
EXECUTE uspContent_SelectOne '132'
16/04/2009 00:00:00
EXECUTE uspContent_SelectOne '127'
16/04/2009 00:00:00
EXECUTE uspFiles_SelectOne_NoFileData '60'
EXECUTE uspArticleAttachments_SelectOne_ArticleId_AttachmentId '3','3'
EXECUTE uspAttachment_SelectOne '3'
EXECUTE uspContent_SelectOne '133'
16/04/2009 00:00:00
EXECUTE uspContent_SelectOne '131'
16/04/2009 00:00:00
EXECUTE uspAttachment_SelectAll
EXECUTE uspArticleAuthors_SelectAll_ArticleId '3'
EXECUTE uspAuthors_SelectAll_Letter_LastName 'A'
EXECUTE uspContent_SelectOne '129'
18/09/2008 00:00:00
EXECUTE uspContent_SelectOne '7'
18/09/2008 00:00:00
EXECUTE uspContent_SelectOne '8'
18/09/2008 00:00:00
EXECUTE uspContent_SelectOne '9'
18/09/2008 00:00:00
EXECUTE uspContent_SelectOne '10'
18/09/2008 00:00:00
EXECUTE uspContent_SelectOne '11'
18/09/2008 00:00:00
EXECUTE uspFiles_SelectAll_NoFileData 

I can’t understand why. I am using ASP.NET/C#, SQL Server 2005 and MS Enterprise Library 4.1.

UPDATE 1

I checked the application culture settings and got this. For each date field request, I checked the culture. In the image below, you can see how culture is changing from the US to the UK:

image change cuture http://www.craigmoliver.com/cultureissue.jpg

web.config :

<globalization culture="en-US" uiCulture="en-US" requestEncoding="utf-8" responseEncoding="utf-8" enableClientBasedCulture="false" />
+3
7

, ? /UICulture Accept-Language HTTP-? , , , , en-US, - en-GB?

+4

.

: -?

+3

, Thread.CurrentThread.CurrentCulture. .

+1

, "Convert.ToDate", :

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

, . - en-US.

!

0

DataSets, XSD ( DataSet.ReadXmlSchema), XSD msdata:Locale, DataSet , web.config. , XSD.

, , .

, - Enterprise Library. , , - (en-UK). , - .

0

? , @Page - . , - .

0

You can also check your procedures using the SET DATEFORMAT statement. In SQL Server, you can change the intuition of date values ​​in the context of a procedure so that the database parses dates differently. Following code

SET DATEFORMAT 'DMY';
SELECT CAST('1-4-2009' AS date);
SET DATEFORMAT 'MDY';
SELECT CAST('1-4-2009' AS date);

Returns the following results on my PC

2009-04-01
2009-01-04

SQL Server therefore interprets string values ​​as dates in different ways.

0
source

Source: https://habr.com/ru/post/1706838/


All Articles