gpt4 book ai didi

C# Entity Framework 查询存储过程错误 "Culture is not supported"

转载 作者:太空宇宙 更新时间:2023-11-03 14:47:59 28 4
gpt4 key购买 nike

我正在尝试从包含一些韩文文本的数据库中查询数据。这同样适用于其他没有任何韩国信息的数据库。我应该设置一些文化信息吗?我找到的数据库排序规则是 Korean_Wansung_Unicode_CI_AS

using (DBModel data = new DBModel())
{
//command and parameters prepared here
var SqlCommand = "ProcedureName @LastUpdateDate, @LastUpdateTS";
var SqlParams = new SqlParameter[]
{
new SqlParameter { ParameterName = "@LastUpdateDate", Value =lastDatetime, Direction = System.Data.ParameterDirection.Input },
new SqlParameter { ParameterName = "@LastUpdateTS", Value =lastTS, Direction = System.Data.ParameterDirection.Input }
};
return data.Database.SqlQuery<BP>(SqlCommand, SqlParams).ToList();
}

Database.SqlQuery 抛出 CultureNotFoundException,如下所示

Culture is not supported.

Parameter name: culture

66578 (0x10412) is an invalid culture identifier.

at System.Globalization.CultureInfo.GetCultureInfo(Int32 culture)
at System.Globalization.CompareInfo.GetCompareInfo(Int32 culture)
at System.Data.ProviderBase.FieldNameLookup.LinearIndexOf(String fieldName, CompareOptions compareOptions)
at System.Data.ProviderBase.FieldNameLookup.IndexOf(String fieldName)
at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.TryGetColumnOrdinalFromReader(DbDataReader storeDataReader, String columnName, Int32& ordinal)
at System.Data.Entity.Core.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndClrType(DbDataReader reader, Type type, MetadataWorkspace workspace)
at System.Data.Entity.Core.Objects.ObjectContext.InternalTranslate[TElement](DbDataReader reader, String entitySetName, MergeOption mergeOption, Boolean streaming, EntitySet& entitySet, TypeUsage& edmType)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryInternal[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass69`1.<ExecuteStoreQueryReliably>b__68()
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass69`1.<ExecuteStoreQueryReliably>b__67()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQueryReliably[TElement](String commandText, String entitySetName, ExecutionOptions executionOptions, Object[] parameters)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteStoreQuery[TElement](String commandText, ExecutionOptions executionOptions, Object[] parameters)
at System.Data.Entity.Internal.InternalContext.<>c__DisplayClass14`1.<ExecuteSqlQuery>b__13()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

我尝试了同样的方法,用普通的旧方法将数据检索到数据表中,不知何故它起作用了。那么EF中需要设置什么呢?

            var SqlCommand = "exec ProcedureName '2018-11-11 16:30:00', 163000";                   

string constring = System.Configuration.ConfigurationManager.ConnectionStrings["Connection"].ToString();
SqlConnection con = new System.Data.SqlClient.SqlConnection(constring);
SqlCommand cmd = new SqlCommand(SqlCommand, con);
cmd.CommandType = System.Data.CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

最佳答案

此处的 LCID 似乎 是在 TDS 解析器中设置的 - 特别是 TdsParser.TryProcessEnvChange;这意味着您无法在您的 C# 代码中做任何改变。

我只能提供两个建议:

  1. 尝试在您查询的机器上安装相关的韩语语言包;可能是现在它无法解析文化,但是将语言包安装到 Windows 中有助于它理解 - 未测试
  2. 看看你是否可以更改数据库排序规则;现在显然,这是一个具有巨大影响的巨大变化,所以不应该轻率地进行 - 理想情况下只有在所有其他方法都失败后才能进行

当然,第三个选项可能是查看 EF 或 SqlClient 人员(重叠团队)是否在 github 上响应;他们在 dotnet/corefx 下。然而,公共(public) github 主要是“.NET Core”,所以一个很好的起点是确认同样的问题发生在 .NET Core 上;如果是这样,与人打交道会容易得多。

免责声明:此处的所有内容均来自对调用树的黑客攻击,我声称对此具有权威性。

关于C# Entity Framework 查询存储过程错误 "Culture is not supported",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53277604/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com