问题描述
例如,如果我可以执行以下操作,那就太好了
For example, it would be great if I could do the following:
private void SetSessionGlobalization(Oracle.DataAccess.Client.OracleConnection aConnection)
{
System.Globalization.CultureInfo lCultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
aConnection.SetSessionInfo(lCultureInfo);
}
但是这不起作用,因为SetSessionInfo将OracleGlobalization类作为参数而不是CultureInfo作为参数!
But that does not work because SetSessionInfo takes a OracleGlobalization class as a parameter, not a CultureInfo!
这也不起作用:
private void SetSessionGlobalization(Oracle.DataAccess.Client.OracleConnection aConnection)
{
Oracle.DataAccess.Client.OracleGlobalization lClientGlobalization = Oracle.DataAccess.Client.OracleGlobalization.GetClientInfo());
aConnection.SetSessionInfo(lClientGlobalization);
}
因为GetClientInfo获取Oracle的客户端全球化设置版本,而不是Windows.
Because GetClientInfo gets Oracle's version of the client globalization settings, not Windows.
我在这里想念什么?如何将数据库连接会话设置为与线程所使用的会话相同(默认情况下与Windows相同)?
What am I missing here? How do I set my database connection session to be the same as that used by my thread (which will be the same as Windows by default)?
推荐答案
我认为您必须手动分配每个属性.就是这样.
I think you have to assign each property manually.It would be like this.
private void SetSessionGlobalization(Oracle.DataAccess.Client.OracleConnection aConnection)
{
OracleGlobalization info = aConnection.GetSessionInfo();
System.Globalization.CultureInfo lCultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
var ri = new System.Globalization.RegionInfo(lCultureInfo.LCID);
info.Calendar = lCultureInfo.Calendar.GetType().Name.Replace("Calendar", String.Empty);
info.Currency = ri.CurrencySymbol;
info.DualCurrency = ri.CurrencySymbol;
info.ISOCurrency = ri.ISOCurrencySymbol;
info.DateFormat = lCultureInfo.DateTimeFormat.ShortDatePattern + " " + lCultureInfo.DateTimeFormat.ShortTimePattern.Replace("HH", "HH24").Replace("mm", "mi");
info.DateLanguage = System.Text.RegularExpressions.Regex.Replace(lCultureInfo.EnglishName , @" \(.+\)",String.Empty);
info.NumericCharacters = lCultureInfo.NumberFormat.NumberDecimalSeparator + lCultureInfo.NumberFormat.NumberGroupSeparator;
info.TimeZone = String.Format("{0}:{1}", TimeZoneInfo.Local.BaseUtcOffset.Hours, TimeZoneInfo.Local.BaseUtcOffset.Minutes);
info.Language = ...
info.Territory = ...
info.TimeStampFormat = ...
info.TimeStampTZFormat = ...
try {
aConnection.SetSessionInfo(info);
} catch ( OracleException err ) {
MessageBox.Show(err.Message);
}
}
您必须进行几种翻译,例如日期格式或地区/语言.希望您对如何操作有所了解.
You have to to several kind of translations, e.g. for Date format or Region/Language. I hope you got an idea how to do it.
请注意,某些(重要)设置(例如ClientCharacterSet
)是只读/只读的,这些值是从注册表"或环境"变量派生的,并在打开连接时进行设置.
Note some (important) settings (e.g. ClientCharacterSet
) are Read/only, these values are derived from Registry or Environment variables and are set while opening the connection.
因此,首选方法是使用注册表或环境变量,则不必设置OracleGlobalization
.
So, the preferred way is to use Registry or Environment variables, then you don't have to set OracleGlobalization
.
这篇关于如何将Oracle会话的全球化设置为与.NET中的Windows相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!