如何在C#中以指定语言(英语)显示MSSQL异常消息?

发布于 2024-09-29 21:03:54 字数 88 浏览 0 评论 0原文

如何在 C# 中以指定语言(英语)而不是 UI 语言显示 MSSQL 异常消息?

我尝试更改线程的 CultureInfo 但它没有改变任何内容。

How to display MSSQL exception messages in C# in a specified language (English) instead of in the UI language?

I tried changing the thread's CultureInfo but it didn't change anything.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

他是夢罘是命 2024-10-06 21:04:20

Current Language=English 添加到连接字符串。

Add Current Language=English to the connection string.

神经暖 2024-10-06 21:04:19

:( 不幸的是,我心中没有好的解决方案,

我只能说在单独的 catch 块中处理每个异常。

例如:

catch(TimoutException ex) { }

catch(CommunicationException ex) { }

并从全局资源中获取适当的异常消息。

:( Unfortunately there is no good solution in my mind,

All i can say is to handle each exception in separate catch block.

like:

catch(TimoutException ex) { }

catch(CommunicationException ex) { }

and get appropriate exception message from your global resource.

ヅ她的身影、若隐若现 2024-10-06 21:04:18

该消息是在 SQL Server 上生成的。框架应该如何进行翻译?

我所做的是将异常分为两种类型:

  • 可以处理并因此转换为 CurrentUICulture 的异常。请记住,该错误很可能是非常技术性的,需要翻译成用户可以理解的内容。因此,即使翻译了外键异常也不是很有帮助。
  • 无法处理的异常会被翻译成一般消息,例如“抱歉给您带来不便...”

然后将异常记录到应用程序日志等中。我更喜欢使用英文文本。这保证了大多数开发人员或系统管理员都了解正在发生的事情。

对于错误处理,您可以查看 ELMAH

The message is generated on the SQL Server. How should the Framework do the translation?

What I do is to divide the exceptions in two types:

  • Exception that can be handled and therefore translated into the CurrentUICulture. Keep in mind that the error is most likely very technical and needs to be translated into something the user understands. So a foreign-key exception is not very helpfull even if translated.
  • Exception that can't be handled and that is translated into a general message like 'Sorry for the inconvenience...'

Then for logging the exception into the application log etc. I prefer using the english text. This garanties that most of the developer or system administrators understand what is going on.

For error handling you might take a look at ELMAH.

岁月如刀 2024-10-06 21:04:17

它与CultureInfo无关,如果您想在异常消息中使用不同的语言,您需要安装.NetFramework语言更新。例如,如果您安装阿拉伯语 .net 框架,则异常消息将显示为阿拉伯语

It is not related with CultureInfo, if you want to use different languages in your Exception messages, you need to install .NetFramework Language update. For ex, if you install arabic .net framework, you exception messaages appear like arabic

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文