如何检查哪个语言环境是在其下运行的.NET应用程序,而无需访问其源代码?

时间:2022-08-29 07:30:00

Context: I'm in charge of running a service written in .NET. Proprietary application. It uses a SQL Server database. It ran as a user member of the Administrators group in the local machine. It worked alright before I added the machine to a domain.

上下文:我负责运行用.NET编写的服务。专有应用。它使用SQL Server数据库。它作为本地计算机中Administrators组的用户成员运行。在我将机器添加到域之前,它工作正常。

So, I added the machine to a domain (Win 2003) and changed the user to a member of the Power Users group and now, the

因此,我将计算机添加到域(Win 2003)并将用户更改为Power Users组的成员,现在,将其更改为

Problem: Some of the SQL sentences it tries to execute are "magically" in spanish localization (where , separates floating point numbers instead of .), leading to errors.

问题:它尝试执行的一些SQL语句在“西班牙语本地化”中是“神奇地”(其中,分隔浮点数而不是。),导致错误。

There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

INSERT语句中的列少于VALUES子句中指定的值。 VALUES子句中的值数必须与INSERT语句中指定的列数相匹配。在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection)

Operating System and Regional Settings in the machine are in English. I asked the provider of the application and he said:

机器中的操作系统和区域设置为英语。我问应用程序的提供者,他说:

Looks like you have a combination of code running under Spanish locale, and SQL server under English locale. So the SQL expects '15.28' and not '15,28'

看起来你有一个在西班牙语语言环境下运行的代码和在英语语言环境下运行的SQL服务器的组合。所以SQL期望'15 .28'而不是'15,28'

Which looks wrong to me in various levels (how can SQL Server distinguish between commas to separate arguments and commas belonging to a floating point number?).

这在各个级别上看起来都不对(SQL Server如何区分逗号以分隔参数和属于浮点数的逗号?)。

So, the code seems to be grabbing the spanish locale from somewhere, I don't know if it's the user it runs as, or someplace else (global policy, maybe?). But the question is

所以,代码似乎是从某个地方抓住西班牙语语言环境,我不知道它是运行的用户,还是其他地方(全局策略,也许?)。但问题是

What are the places where localization is defined on a machine/user/domain basis?

在机器/用户/域基础上定义本地化的地方是什么?

I don't know all the places I must search for the culprit, so please help me to find it!

我不知道我必须寻找罪魁祸首的所有地方,所以请帮我找到它!

5 个解决方案

#1


3  

There are two types of localisation in .NET, both the settings for the cultures can be found in these variables (fire up a .NET command line app on the machine to see what it says):

在.NET中有两种类型的本地化,可以在这些变量中找到文化的设置(在计算机上启动.NET命令行应用程序以查看它的内容):

System.Thread.CurrentThread.CurrentCulture & System.Thread.CurrentThread.CurrentUICulture

System.Thread.CurrentThread.CurrentCulture&System.Thread.CurrentThread.CurrentUICulture

http://msdn.microsoft.com/en-us/library/system.threading.thread_members.aspx

They relate to the settings in the control panel (in the regional settings part). Create a .NET command line app, then just call ToString() on the above properties, that should tell you which property to look at.

它们与控制面板中的设置有关(在区域设置部分中)。创建一个.NET命令行应用程序,然后在上面的属性上调用ToString(),它应该告诉您要查看哪个属性。

Edit:

It turns out the setting for the locales per user are held here:

事实证明,每个用户的语言环境设置保存在此处:

HKEY_CURRENT_USER\Control Panel\International

It might be worth inspecting the registry of the user with the spanish locale, and comparing it to one who is set to US or whichever locale you require.

可能值得检查具有西班牙语语言环境的用户的注册表,并将其与设置为US的用户或您需要的任何语言环境进行比较。

#2


1  

You can set it in the thread context in which your code is executing.

您可以在执行代码的线程上下文中进行设置。

System.Threading.Thread.CurrentThread.CurrentCulture

#3


0  

Great, I created the console app and indeed, the app is not crazy, CurrentCulture is in spanish, but for THAT User in THAT machine only. If I run the console app as another user it returns english for all cultures.

太棒了,我创建了控制台应用程序,实际上,应用程序并不疯狂,CurrentCulture是西班牙语,但仅限于那台用户。如果我以另一个用户身份运行控制台应用程序,则返回所有文化的英语。

Should I open a new question asking where are user-wise locale settings?

我应该打开一个新问题,询问用户明确的区域设置在哪里?

#4


0  

Well if it's user specific, check out the Regional and Language Options control panel.

如果它是特定于用户的,请查看“区域和语言选项”控制面板。

<rant>On a side note, kick the developer for not being culture aware when using strings.</rant>

在旁注中,当开发人员使用字符串时不要注意文化。

#5


0  

Found out why it happened in that machine only. It was the only one where I actually logged into with that user, then the domain controller set the regional settings as spanish for it.

找出为什么它只发生在那台机器上。这是我实际登录该用户的唯一一个,然后域控制器将区域设置设置为西班牙语。

#1


3  

There are two types of localisation in .NET, both the settings for the cultures can be found in these variables (fire up a .NET command line app on the machine to see what it says):

在.NET中有两种类型的本地化,可以在这些变量中找到文化的设置(在计算机上启动.NET命令行应用程序以查看它的内容):

System.Thread.CurrentThread.CurrentCulture & System.Thread.CurrentThread.CurrentUICulture

System.Thread.CurrentThread.CurrentCulture&System.Thread.CurrentThread.CurrentUICulture

http://msdn.microsoft.com/en-us/library/system.threading.thread_members.aspx

They relate to the settings in the control panel (in the regional settings part). Create a .NET command line app, then just call ToString() on the above properties, that should tell you which property to look at.

它们与控制面板中的设置有关(在区域设置部分中)。创建一个.NET命令行应用程序,然后在上面的属性上调用ToString(),它应该告诉您要查看哪个属性。

Edit:

It turns out the setting for the locales per user are held here:

事实证明,每个用户的语言环境设置保存在此处:

HKEY_CURRENT_USER\Control Panel\International

It might be worth inspecting the registry of the user with the spanish locale, and comparing it to one who is set to US or whichever locale you require.

可能值得检查具有西班牙语语言环境的用户的注册表,并将其与设置为US的用户或您需要的任何语言环境进行比较。

#2


1  

You can set it in the thread context in which your code is executing.

您可以在执行代码的线程上下文中进行设置。

System.Threading.Thread.CurrentThread.CurrentCulture

#3


0  

Great, I created the console app and indeed, the app is not crazy, CurrentCulture is in spanish, but for THAT User in THAT machine only. If I run the console app as another user it returns english for all cultures.

太棒了,我创建了控制台应用程序,实际上,应用程序并不疯狂,CurrentCulture是西班牙语,但仅限于那台用户。如果我以另一个用户身份运行控制台应用程序,则返回所有文化的英语。

Should I open a new question asking where are user-wise locale settings?

我应该打开一个新问题,询问用户明确的区域设置在哪里?

#4


0  

Well if it's user specific, check out the Regional and Language Options control panel.

如果它是特定于用户的,请查看“区域和语言选项”控制面板。

<rant>On a side note, kick the developer for not being culture aware when using strings.</rant>

在旁注中,当开发人员使用字符串时不要注意文化。

#5


0  

Found out why it happened in that machine only. It was the only one where I actually logged into with that user, then the domain controller set the regional settings as spanish for it.

找出为什么它只发生在那台机器上。这是我实际登录该用户的唯一一个,然后域控制器将区域设置设置为西班牙语。